Problem:


Score : 300 points

Problem Statement

Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:

Throw the die. The current score is the result of the die.

As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.

The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.

You are given N and K. Find the probability that Snuke wins the game.

Constraints

1 ≤ N ≤ 10^5

1 ≤ K ≤ 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.

Sample Input 1

3 10

Sample Output 1

0.145833333333

If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^4 = \frac{1}{48}.

If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^3 = \frac{1}{24}.

If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^2 = \frac{1}{12}.

Thus, the probability that Snuke wins is \frac{1}{48} + \frac{1}{24} + \frac{1}{12} = \frac{7}{48} \simeq 0.1458333333.

Sample Input 2

100000 5

Sample Output 2

0.999973749998



Sample input:
3 10


Sample output:
0.145833333333

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
import math
n, k = getList()
pn = 1 / n

ans = 0
for i in range(1,n+1):
    if i >= k:
        ans += 1
    else:
        kaisu = math.ceil(math.log2(k/i))
        ans += 0.5 ** kaisu
    #print(ans, kaisu)#

print(ans * pn)

Submission status: Accepted

Solution code:
from math import log2,ceil
N,K = map(int,input().split())

r = [0.5]
for i in range(50):
    r.append(r[-1] / 2)

ans = 0
for n in range(1,N+1):
    if n > K-1:
        ans += 1
        continue
    c = ceil(log2(K/n))
    ans += r[c-1]
print(ans/N)

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7
BN = 2 ** 30

N, K = map(int, raw_input().split())
ans = 0
for i in range(1, N + 1):
    num = i
    S = BN
    while num < K:
        num *= 2
        S /= 2
    ans += S
print ans * 10 ** 15 / (BN * N) / float(10 ** 15)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = 0
for i in range(n):
    score = i + 1
    times = 0
    while score < k:
        times += 1
        score *= 2
    if times == 0:
        p += 1 / n
    else:
        p += 0.5 ** times / n
print(p)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

res = 0
for i in range(N):
    p = i+1
    for j in range(30):
        if p * (2**j) >= K:
            res += 1 / N / (2**j)
            break

print(res)

Submission status: Accepted

Solution code:
N,K = map(int,input().split(" "))

j = 0
i = 1
while i <= N:
    s = 1
    while i * s < K:
        s *= 2
    j += 1 / s
    i += 1 

print(j / N)

Submission status: Accepted

Solution code:
import math

N, K = list(map(int, input().split(" ")))

prob = 0
for i in range(N):
  if i + 1 < K:
    n = math.ceil(math.log(K / (i + 1), 2))
    prob += 1 / (N * (2 ** n))
  else:
    prob += (N - K + 1) / N
    break

print(prob)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))

Ans = 0
for i in range(1, N + 1):
  cnt = 1
  k = i
  while k < K:
    k *= 2
    cnt *= 2
  Ans += 1 / cnt / N

print(Ans)

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
twos = [1]
i = 0
while 2*twos[i] <= 10**5:
    twos.append(twos[i]*2)
    i += 1
twos.append(twos[-1]*2)

ans = 0
for i in range(1,n+1):
    temp = 0
    while twos[temp] * i <= k-1:
        temp += 1
    ans += 1/n * 1/twos[temp]
print(ans)

Submission status: Accepted

Solution code:
def calc(x):
    return max((-(-K//x)-1).bit_length(), 0)
N, K = map(int, input().split())
ans = 0
for i in range(1, N+1):
    ans += 2**(20-calc(i))
print(ans/(2**20*N))

Submission status: Accepted

Solution code:
from math import log2, floor
n, k = map(int, input().split())
a = 1/n
ans = 0
for i in range(1, n+1):
    if i >= k:
        ans += a
        continue
    j = int(log2(k/i)) + 1
    if i*2**(j-1) == k:
        j -= 1
    ans += a/2**j
print(ans)

Submission status: Accepted

Solution code:
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans

def getval(a,k):
    val=1
    while(a<k):
        a*=2
        val/=2
    return val
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    n,k= map(int, sys.stdin.readline().split(' '))
    ans=0
    for i in range(1,n+1):
        ans+=getval(i,k)
    print(ans/n)
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Submission status: Accepted

Solution code:
import math

N, K = map(int, input().split())

ans = 0.

for i in range(1, N + 1):
    if i < K:
        ans += (1 / N) * (1 / (2 ** math.ceil(math.log2(K / i))))
    else:
        ans += 1 / N

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
prob = [0.0] * k
for i in reversed(range(k)):
    if i * 2 >= k:
        prob[i] = 0.5
    else:
        prob[i] = prob[i * 2] / 2
ans = 0
for i in range(1, n+1):
    if i >= k:
        ans += 1
    else:
        ans += prob[i]
print(ans / n)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = 0

for i in range(1, n+1):
  cnt = 0
  while i < k:
    i *= 2
    cnt += 1
  p += 1/n * (1/2) ** cnt
  
print(p)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

n = N
rate = 0
res = 0
while n > 0:
    if n >= K*(1/2)**rate:
        res += 1/N * (1/2)**rate
        n -= 1
    else:
        rate += 1
print(res)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
    p=0; x=i
    while x<k:
        x*=2
        p+=1
    ans+=(0.5**p)/n
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

ans = 0
for i in reversed(range(1, N+1)):
  n = 1
  while i < K:
    n <<= 1
    i <<= 1
  ans += 1 / n
print(ans / N)

Submission status: Accepted

Solution code:
def dice_and_coin(N: int, K: int)->int:
    ans = 0

    for n in range(1, N+1):
        if n < K:
            c = 0
            while n < K:
                n <<= 1
                c += 1

            ans += 1 / (1 << c)
        else:
            ans += 1

    return ans / N


if __name__ == "__main__":
    N, K = map(int, input().split())

    ans = dice_and_coin(N, K)
    print('{:.10f}'.format(ans))

Submission status: Accepted

Solution code:
n,k = (int(i) for i in input().split())

res = 0
for i in range(1,n+1):
    cnt = 0
    now = i
    while True:
        if now >= k:
            break    
        now = now*2
        cnt+=1
    
    res += 1/(n*2**cnt)

print(res)

Submission status: Accepted

Solution code:
import math
from functools import reduce

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,k = get_nums_l()

ans = 0
for init_score in range(1,n+1):
    score = init_score
    # 勝つために連続で表を出さなければならない回数
    need = 0
    while score < k:
        need += 1
        score *= 2

    rate = 1 / 2**need
    ans += rate / n

print(ans)

Submission status: Accepted

Solution code:
from math import ceil, log2

N, K = map(int, input().split())

ans = 0
for i in range(1, N + 1):
    if i >= K:
        ans += 1
    else:
        ans += 1 / (2 ** ceil(log2(K / i)))
    # 最後にNで割る
ans /= N
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N,K = map(int,input().split())

ans = 0

for i in range(1,N+1):
    prob = 1/N
    score = i
    
    while(score < K):
        score *= 2
        prob *= 0.5
        
    ans += prob
    
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import math

N,K=map(int,input().split())
ANS=max(0,N-K+1)


#print(ANS)

for i in range(1,30):
    ANS+=max(0,(N-math.ceil(K*pow(1/2,i))+1))*pow(1/2,i)-max(0,(N-math.ceil(K*pow(1/2,i-1))+1))*pow(1/2,i)

print(ANS/N)

Submission status: Accepted

Solution code:
N,K = map(int,(input().split()))
prob = 0
for i in range(N):
    tmp = i+1
    tmpProb=1
    while tmp < K:
        tmp*=2
        tmpProb/= 2
    prob += tmpProb
    
print(prob/N)

Submission status: Accepted

Solution code:

from collections import defaultdict

def get_renzokuomote(goal, now_num):
    count = 0
    while now_num < goal:
        now_num *= 2
        count += 1
    return count



def main():
    saikoro, goal = map(int, input().split())
    data = defaultdict(float)
    ans = 0
    for i in range(1, saikoro + 1):
        now_num = i
        if now_num % 2 == 0:
            data[now_num] = data[now_num // 2] * 2
        else:
            rennzoku_omote = get_renzokuomote(goal, now_num)
            if rennzoku_omote == 0:
                ans += (saikoro + 1 - now_num) / saikoro
                break
            data[i] = (0.5 ** rennzoku_omote) / saikoro



    for ele in data.values():
        ans += ele
    print(ans)





if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())


def f(x):
    k = 0
    while x < K:
        x *= 2
        k += 1
    return k


ans = sum(
    1 / (2**f(i))
    for i in range(1, N + 1)
) / N

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
deme=[0]*n
for i in range(n):
    now=i+1
    count=0
    while now<k:
        now*=2
        count+=1
    deme[i]=(1/2)**count
print(sum(deme)/n)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,k = li()
ans = 0

for i in range(1, n+1):
    cur = i
    cnt = 0
    while cur < k:
        cnt += 1
        cur *= 2

    ans += (1/n) * (1/pow(2, cnt))

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,K = inpl()

ans = 0
for n in range(1,N+1):
    tmp = 1/N
    now = n
    while now < K:
        now *= 2
        tmp /= 2
    ans += tmp

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, K = list(map(int, input().split()))

cnts = []
for n in range(1, N + 1):
    cnt = 0
    while n * (2 ** cnt) < K:
        cnt += 1
    # cnt 回連続で表なら K を超える
    cnts.append(1 / 2 ** cnt)

print(sum(cnts) / len(cnts))

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
ans = 0
import math
for i in range(1,n+1):
    if i < k :
        ans += 1/(2**float(math.ceil(math.log2(float(k/i)))))
    else :
        ans += 1
print(float(ans/n))

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split() ))

prob_sum = 0

for i in range(1 , n+1):
	now = i
	prob = 1.0

	while now < k:
		now *= 2
		prob /= 2
	prob_sum += prob
print(prob_sum / n)

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]

proball = 0
for i in range(1, N+1):
  prob = 1/N
  point = i
  while(point < K):
    point *= 2
    prob *= (1/2)
  proball += prob
  
print(proball)

Submission status: Accepted

Solution code:
import math


def main():
    N, K = map(int, input().split())
    ans = 0
    for i in range(1, N+1):
        x = math.ceil(math.log(-(-K//i), 2))
        ans += 1/(2**x)
    print(ans/N)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def doubling(i, k):
    while i < k:
        i *= 2
    return i


n, k = map(int, input().split())
p = 0
for i in range(1, n + 1):
    p += (i / doubling(i, k)) / n
print(p)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, K: int):
    acc = 0
    for i in range(1, N+1):
        p = max(0, int(ceil(log2(K / i))))
        acc += (1 / N) * (1 / 2) ** p
    return acc 


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    result = solve(N, K)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
for i in range(1, n+1):
    cnt=0
    while i<k:
        cnt+=1
        i*=2
    ans+=0.5**cnt
print(ans/n)

Submission status: Accepted

Solution code:
ans = 0

n,k = map(int,input().split())
prob = 1/n

for i in range(1,n+1):
	
	num = i
	count = 0
	while(i < k):
		i = i*2
		count += 1

	prob2 = pow(2,count)

	an = (1 / prob2)
	# print(prob2)
	ans += an

ans = ans * prob
print(ans)

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())

ans = 0

for i in range(1,n+1):
      x = math.ceil(math.log2((k/i)))
      if x >= 1:
            ans += (1/n)*(1/2)**x
      else:
            ans += (1/n)
      #print(math.log2((k/i)))
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3

#import numpy as np
#import scipy, scipy.special

# Python 3 modules: https://docs.python.org/3/library/

import math, itertools, operator
from math import *
from math import factorial as fact
from itertools import permutations, combinations
from functools import reduce
# Use scipy for stats: https://docs.scipy.org/doc/scipy/reference/stats.html
# Before Python 3.5
from fractions import gcd

inf = float('inf')

def lcm(a, b):
    return a * b // gcd(a,b)

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(inp = input, sep = ' ', conv = int):
    return map(conv, inp().split(sep = sep))

################################################################################


N, K = input_ints()

P = .0
for n in range(1, N+1):
    i = 0
    c = 0
    while n < K:
        n *= 2
        c += 1
    P += pow(.5, c) / N
print(P)

Submission status: Accepted

Solution code:
import math
N,K=map(int,input().split())
# print(sum([0.5**math.ceil(math.log2(K/n)) for n in range(1, N)])/N)
print(sum([0.5**max(0, math.ceil(math.log2(K/n))) for n in range(1, N+1)])/N)

Submission status: Accepted

Solution code:
import math


def required_num_coins(x, k):
    return max(0, math.ceil(math.log(k / x, 2)))


def compute_prob(n, k):
    return sum(2 ** (-required_num_coins(x, k)) for x in range(1, n + 1)) / n


def main():
    n, k = (int(z) for z in input().split())
    res = compute_prob(n, k)
    print("{:.12f}".format(res))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())

res = 0.0

for i in range(1,n+1):
    p = 0
    s = i
    while s < k:
        s *= 2
        p += 1
    res += pow(0.5,p)
print(res/n)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,k = LI()
    s = input()
    for i in range(k-1):
        print(s[i],end = "")
    print(s[k-1].lower(),end = "")
    for i in range(k,n):
        print(s[i],end = "")
    print()
    return

#B
def B():
    s = S()
    k = int(s[0])*10+int(s[1])
    l = int(s[2])*10+int(s[3])
    if k == 0:
        if l == 0:
            print("NA")
        elif l < 13:
            print("YYMM")
        else:
            print("NA")
    elif k < 13:
        if l == 0:
            print("MMYY")
        elif l < 13:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    else:
        if l == 0:
            print("NA")
        elif l < 13:
            print("YYMM")
        else:
            print("NA")

#C
def C():
    n,k = LI()
    ans = 0
    for i in range(1,n+1):
        l = k/i
        ans += 1/n*1/(2 << max(0,math.ceil(math.log(l,2))))
    print(ans*2)
    return

#D
def D():

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

Solution code:
n,k=map(int, input().split()) 
p=0
for i in range(n):
    dice=i+1
    k_=k/dice
    p_=1
    if dice<k:
        while(k_>1):
            k_/=2
            p_*=0.5
    p+=p_/n
print(p)

Submission status: Accepted

Solution code:
N, K = [int(elem) for elem in input().split()]

num_omotes_list = []
for i in range(1, N + 1):
    num_omotes = 0
    current_score = i
    while current_score < K:
        num_omotes += 1
        current_score *= 2
    num_omotes_list.append(num_omotes)

max_num_omotes = max(num_omotes_list)
denominator = 1 << max_num_omotes
numerator = sum(1 << (max_num_omotes - num_omotes) for num_omotes in num_omotes_list)
print(numerator / denominator / N)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
def f(x):
    l = 0
    while x < k:
        x *= 2
        l += 1
    return l
res = 0
for i in range(1, n + 1):
    res += pow(0.5, f(i))
print(res / n)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import math
N, K = map(int, input().split())
ans = 0
pows = []
for n in range(1, N + 1):
    p = n
    seq = 0
    while p < K:
        seq += 1
        p *= 2
    pows.append(seq)

s = sum(pows)
c = 0
for p in pows:
    c += pow(2, s - p)
print(c / (pow(2, s) * N))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
for k in range(1,N+1):
    t=0
    s=1
    while k*pow(2,t)<K:
        t+=1
        s*=0.5
    ans+=(1/N)*s
    #print(s,ans)
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
prob = 0
for nn in range(1, n+1):
  coin_prob = 1
  while nn < k:
    coin_prob *= 0.5
    nn *= 2
  prob += coin_prob * 1.0 / n
print(prob)

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
ans = 0
for i in range(1, n+1):
  cur = i
  cnt = 0
  while cur<k:
    cur *= 2
    cnt += 1
  ans += pow(2, -cnt)/n
print(ans)

Submission status: Accepted

Solution code:
n, k = input().split()
n, k = int(n), int(k)
from math import log2 as lg
from math import ceil

corr = 0

for i in range(1, n+1):
    if i >= k:
        corr += 1/n
        continue
    need = 2 ** (-1 * ceil(lg(k / i)))
    corr += ((1/n) * need)

print(corr)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K):
    ans = 0
    for i in range(1, N+1):
        if i < K:
            n = math.ceil(math.log2(K / i))
        else:
            n = 0
        ans += (1./N) * (1./(2**n))
    return ans


def main():
    N, K = read_int_n()
    print(slv(N, K))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
range = xrange
input = raw_input

N,K = [int(x) for x in input().split()]

prob = 0
for k in range(1,N+1):
    p = 1.0/N
    score = k
    while score < K:
        score *= 2
        p /= 2
    prob += p

print `prob`

Submission status: Accepted

Solution code:
N, K = map( int, input().split())
ANS = [0]*(N+1)
for i in range(1,N+1):
    if i >= K:
        ANS[i] = 1
    a = i
    t = 0
    while a < K:
        a *= 2
        t += 1
    ANS[i] = 2**(-t)
print(sum(ANS)/N)

Submission status: Accepted

Solution code:
def solve(string):
    n, k = map(int, string.split())
    ans = 0
    for i in range(1, n + 1):
        tmp = i
        p = 1
        while i < k:
            i *= 2
            p /= 2
        ans += p

    return ans / n


if __name__ == '__main__':
    print(solve(input()))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=0
for i in range(n):
  j=n-i
  b=1
  while j<k:b/=2;j*=2
  a+=b
print(a/n)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
INF = float("inf")


def solve(N: int, K: int):

    numer = 0
    for i in range(1, N+1):
        if i < K:
            b = math.ceil(math.log2(K/i))
            numer += 1/(2**b)
        else:
            numer += 1

    print(numer/N)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
from functools import lru_cache
@lru_cache(maxsize=None)
def solve(n):
    if n>=K:
        return 1.0
    else:
        return solve(n<<1) * 0.5
ans = 0
for i in range(N, 0, -1):
    ans += solve(i)
ans /= N
print(ans)

Submission status: Accepted

Solution code:
N,K = list(map(int, input().split()))

p = 0
#1
for i in range(1,N+1):
  pi = 1/N
  score = i
  while score <=K-1:
    score *= 2
    pi *= 0.5
  p += pi

print(p)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())

ans = 0
for i in range(1,N+1):
    a = i
    c = 0
    while True:
        if a >= K:
            break
        a *= 2
        c += 1
    ans += (1/N)*((0.5)**c)
print(ans)

Submission status: Accepted

Solution code:
def p(dice, k):
    times = 0
    score = dice
    while score < k:
        score *= 2
        times += 1

    return 1/(2**times)


n, k = map(int, input().split())
prob = 0.0
for i in range(1, n+1):
    prob += (1.0 / n) * p(i, k)

print(prob)

Submission status: Accepted

Solution code:
from math import log2, ceil
N,K = map(int,input().split())

def it():
    for n in range(1,N+1):
        yield 1/(2**max(0,ceil(log2(K/n))) * N)
print(sum(it()))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
for i in range(1,n+1):
    point = i
    kakuritu = 1/n
    while 1 <= point <= k - 1:
        point = 2 * point
        kakuritu = kakuritu/2
    ans += kakuritu
print(ans)

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())

    ans = 0
    for n in range(1, N+1):
        cnt = 0
        x = n
        while x < K:
            cnt += 1
            x *= 2
        ans += pow(2, -cnt) / N
        # print(n, cnt)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import ceil, log2
n, k = map(int, input().split())
ans = 0.0
for i in range(1, n + 1):
    if k > i:
        ans += (1 / n) * ((1 / 2)**(ceil(log2(k / i))))
    else:
        ans += 1/n
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
for i in range(1, n+1):
  if i >= k:
    ans += 1 / n
  else:
    p = i
    tmp = 1 / n
    while p < k:
      p *= 2
      tmp /= 2
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
from fractions import Fraction
n, k = map(int, input().split())
ans = Fraction(0)
for i in range(1, n + 1):
    d = i
    p = 0
    while d < k:
        d = d << 1
        p += 1
    ans += Fraction(1, pow(2, p) * n)
print('{:.12f}'.format(float(ans)))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
res = 0
for i in range(1, n+1):
	tmp, p = i, 1
	while tmp < k:
		tmp  *= 2
		p *= 0.5
	res += p
print("{:.12g}".format(res/n))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    percent = 1
    point = i
    while K > point:
        percent /= 2
        point *= 2
    ans += percent
print(ans/N)

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.readline
inf = 10 ** 18

N, K = map(int, input().split())

targets = [0] * N
for i in range(N):
    tmp = i + 1
    for j in range(64):
        if (tmp << j) >= K: break
    targets[i] = j

ans = 0
for i in range(N):
    ans += (0.5 ** targets[i])
ans = ans / N

print(ans)

Submission status: Accepted

Solution code:
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    N, K = map(int, line_input())
    sum = 0
    for i in range(1, N+1):
        count = 0
        num = i
        while num < K:
            count += 1
            num *= 2
        sum += (1 / N) * (0.5) ** count
    print(sum)

    return 0
  
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N, K = map(int, raw_input().split())

ans = 0.0
for i in range(1, N+1):
  c = 0
  while i<K:
    i *= 2
    c += 1
  ans += 1.0/N*pow(0.5, c)
print "%.12f"%ans

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
for i in range(1, n+1):
	p = 1/n
	x = i
	while x < k:
		x *= 2
		p /= 2
	ans += p
print("%.12f" % ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N, K = map(int, input().split())

pred_sum = 0.0
for n in range(1, N + 1):
    n2 = n
    cnt = 0
    while n2 < K:
        n2 *= 2
        cnt += 1
    pred_sum += 0.5 ** cnt
print("{:.15f}".format(pred_sum / N))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
num = 0
for i in range(1, N + 1):
    k = i
    tmp = 0
    while k < K:
        tmp += 1
        k *= 2

    num += 1 / (N * 2 ** tmp)

print(num)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
    k=0
    while i<K:
        i*=2
        k+=1
    ans+=1/pow(2,k)/N
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)


def main():
    n,k = LI()
    r = 0

    for i in range(1,n+1):
        t = 0
        while i < k:
            t += 1
            i *= 2
        r += 1 / pow(2,t)

    return '{:0.9f}'.format(r/n)


print(main())

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, K = map(int, input().split())


def solve():
    ans = 0
    for i in range(1, N+1):
        tmp = i
        num = 0
        while tmp < K:
            num += 1
            tmp *= 2
        ans += (1/2)**num
    print(ans/N)


solve()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())

ans = 0
for i in range(1,n+1):
    add = 1/n
    v = i
    while v<k:
        v *= 2
        add /= 2
    ans += add

print('%.15f' % ans)