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

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

Prb = [0]*N
for x in range(N):
  Pt = x +1
  Prb[x] = 1/N
  while Pt < K:
    Pt = Pt * 2
    Prb[x] = Prb[x] * 1/2

print(sum(Prb))

Solution (Python):
n , k = map(int,input().split())
b = 1 / n
ans = 0

for i in range(n):
    a = i + 1
    for j in range(30):
        if a < k:
            a *= 2
        else:
            c = (1 / 2) ** j
            ans += b * c
            break
        
print(ans)

Solution (Python):
N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
    if(i < K):
        point = i
        count = 0
        while(point < K):
            count += 1
            point *= 2
        ans += (1/N)*(1/2)**count
    else:
        ans += (1/N)
print(ans)

Solution (Python):
import sys
import numpy as np
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    l=np.array([(1/2)**(-(-np.log2(K/i if K/i > 1 else 1)//1)) for i in range(1,N+1)])
    print(np.sum(l)/N)
        

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):

import sys

import math 








def main():
    n, k = [int(x) for x in sys.stdin.readline().split()]
        

    probability = 0
    for i in range(1, n + 1):
        if i < k:
            probability += (1 / n) * (1 / 2) ** math.ceil(math.log2(k / i))
        else:
            probability += 1 / n
    
    print(probability)

if __name__ == "__main__":
    main()

Solution (Python):
N,K = map(int,input().split())
import math
s = 0
for i in range(1,N+1):
    if i >= K:
        s += 1
    else:
        n = math.ceil(math.log((K/i),2))
        s += 2**(-n)
ans = s/N
print(ans)

Solution (Python):
import math
n,k=map(int,input().split())
i=1
sum=0.0
for i in range(1,n+1):
    cnt=k/i
    temp=1/n
    
    
    
    
    
    
    m=-(-math.log2(cnt)//1)
    if i < k:
        sum+=temp * (1/2)**m
    else:
        sum+=temp
    
print(sum)

Solution (Python):
import math
n,k=map(int,input().split())
i=1
sum=0.0
for i in range(1,n+1):
    cnt=k/i
    temp=1/n
    
    
    
    
    
    m=math.ceil(math.log2(cnt))

    if i < k:
        sum+=temp * (1/2)**m
    else:
        sum+=temp
    
print(sum)

Solution (Python):
import math
n,k=map(int,input().split())
i=1
sum=0.0
for i in range(1,n+1):
    
    temp=1/n
    cnt=i
    m=0
    while cnt < k:
        cnt*=2
        m+=1
    
    
    
    
    sum+=temp * (1/2)**m
    
print(sum)

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

Solution (Python):
import numpy as np
import math

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

prob = np.maximum((N - K + 1) / N, 0)


end = np.minimum(N, K-1)

for i in range(1, end+1):
    ratio = K / i
    num = math.ceil(math.log2(ratio))
    prob += 1 / N * (0.5 ** num)


print(prob)

Solution (Python):
import sys
import math
input = sys.stdin.readline

MOD = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())
    ans = 0.0

    for i in range(1, N+1):
        c = 0
        if i < K:
            c = math.ceil(math.log(K, 2) - math.log(i, 2))
        
        ans += (1.0 / (2 ** c)) * 1.0/N

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
input = sys.stdin.readline

MOD = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())
    ans = 0.0

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

    print("{0:.20f}".format(ans))


if __name__ == '__main__':
    main()

Solution (Python):
N,K=map(int,input().split())
i=0
q=0 
for j in range(1,N+1):
  while j*(2**i)<K:
    i+=1
  q+=(1/N)*((1/2)**i)
  i=0
print(q)

Solution (Python):
import math
N, K = map(int, input().split())

M = []
x = 1
while x < (10 ** 5) * 2:
    M.append(1 / x)
    x <<= 1

p1 = max((N - K + 1) / N, 0)
p = 0
for i in range(1, min(N + 1, K)):
    t = int(math.log2(K / i)) + 1
    if K % i == 0 and  (K // i) & (K // i - 1) == 0:
        t -= 1
    p += M[t]
ans = p / N + p1
print('{0:.10f}'.format(ans))

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

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

Solution (Python):
a, b = map(int, input().split())
ans = 0

for i in range(1, a+1):
  for j in range(10**5):
    if i*2**j >= b:
      ans += (1/a)*(1/2)**j
      break

print(ans)

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

needl = []
for i in range(n):
    need = max(math.ceil((math.log(k/(i+1),2))), 0) 
    needl.append(need)
    

ansl = []
for i in needl:
    ansl.append((1/2)**i * (1/n))

print(sum(ansl))

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

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

base = 1 / N
ans = 0
for n in range(1, N + 1):
    
    
    count = 0
    for i in range(1,30):
        if K > n:
            n *= 2
            count += 1
        else:
            break
    else:
        ans += 0
    ans += base * ((0.5) ** (count)) 
            
print(ans)

Solution (Python):

import sys
def input():
    return sys.stdin.readline().rstrip()

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

    import math

    res = float(0.0)

    for score in range(1, N+1):
        p = float(1.0/N)
        while K > score:
            score = score * 2
            p = p/2
        res = res + p

    print(res)


if __name__ == '__main__':
    main()

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

ans = 0

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

print(ans)

Solution (Python):
n, k = (int(_) for _ in input().split())
m, q, ans = (n, 0, 0)

while m > 0:
    if k <= m:
        ans += (m - k + 1)/n * 0.5**q
        m = k - 1
    k = k // 2 + k % 2
    q += 1

print(ans)

Solution (Python):
n, k = map(int, input().split())
ary = []
for i in range(n):
	x = i+1
	cnt = 0
	while x < k:
		x *= 2
		cnt += 1
	ary.append(1/(2**cnt))
print (sum(ary)/n)

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

Solution (Python):
tmp = list(map(int, input().split()))
n = tmp[0]
k = tmp[1]

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

print (ans)

Solution (Python):
N,K=map(int,input().split())
L=[1/N for i in range(N)]
for k in range(1,N+1):
  n=0
  while k*(2**n)<K:
    n+=1
  L[k-1]*=1/2**n
print(float(sum(L)))

Solution (Python):
import numpy as np

n, k = map(int, input().split())
e = 0
for i in range(1, n + 1):
    if i < k:
        if (np.log2(k) - np.log2(i)) == int(np.log2(k) - np.log2(i)):
            sh = int(np.log2(k) - np.log2(i))  
        else:
            sh = int(np.log2(k) - np.log2(i) + 1)
        e += (1 / n) * 0.5 ** sh
    else:
        e += (1 / n)
print(e)

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

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

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

Solution (Python):
import math
N, K =map(int, input().split())
p = 0
for i in range(1,N+1):
  p += 0.5**max(math.ceil(math.log2(K/i)),0)
print(p/N)

Solution (Python):

N, K = list(map(int,input().split()))
p = 0
if N <= K:
    for i in range(1,N+1):
        count = 0
        while i < K:
            i = i*2
            count+= 1
        p += (1/(2**count))*(1/N)
    print(p)
elif N > K:
    for i in range(1,N+1):
        count = 0
        while i < K:
            i = i*2
            count+= 1
        p += (1/(2**count))*(1/N)
    print(p)

Solution (Python):
a, b = map(int, input().split())
ans = 0

for i in range(1, a+1):
  tmp = 1
  while i*tmp < b:
    tmp *= 2
  ans += (1/a)*(1/tmp)

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from math import log,ceil
    n,k=map(int,input().split())
    p=[0]*(n+1)
    for i in range(1,n+1):
        p[i]=max(0,ceil(log(k/i)/log(2)))
    ans=0
    for i in range(1,n+1):
        ans+=2**(-p[i])
    print(ans/n)
resolve()

Solution (Python):
n,k=map(int,input().split())
a=[]

for i in range(1,n+1):
  x=0
  while i*(2**x)<k:
    x+=1
  a.append(x)
    
ans=0
for j in range(0,n):
  ans+=(1/n)*(2**(-a[j]))
  
print(ans)

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

ans=0
for i in range(1,n+1):
  if i>=k:
    ans+=1/n
  else:
    dcnt=0
    while i<k:
      i*=2
      dcnt+=1
    ans+=(1/n)*(2**(-dcnt))
print(ans)

Solution (Python):



import math

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

win_rate = 0
for i in range(1, N+1):
    tmp = 0.5**math.ceil(math.log2(K/i))
    if tmp < 1:
        win_rate += tmp/N
    else:
        win_rate += 1/N
print(win_rate)

Solution (Python):
n,k=map(int,input().split())
h=0
for i in range(1,n+1):
  j=0
  while i<k:
    i*=2
    j+=1
  h+=1/(n*2**j)
  
print(h)

Solution (Python):

import math

n,k = map(int, input().split())

p=0
for i in range(1,n+1):
  s = math.log2(k)-math.log2(i)
  s = max(0, math.ceil(s))
  
  p += (1/n)*0.5**s
  
  
print(p)

Solution (Python):


MOD = 10 ** 9 + 7

n, k = map(int, input().split())

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

print(ans)

Solution (Python):
from math import ceil
n, k = map(int, input().split())
ans = 0
 
for i in range(n):
    t = i + 1
    p = 1/n
    while t < k:
        t *= 2
        p *= (1/2)
    ans += p

print(ans)

Solution (Python):
import math
n, k = map(int, input().split())
ans = 0
for i  in range(1, n+1):
  c = math.ceil(math.log(k/i,2))
  if c < 0:
    c = 0
  ans += 1 / n * (0.5) ** c
print('{:.12f}'.format(ans))

Solution (Python):
import math

tol = 10 ** -9

(n, k) = map(int, input().split())


def calc_exponent(k, i):
    tmp = math.log2(k / i)
    tmp2 = int(tmp)
    return tmp2 if 10 ** -10 > abs(tmp - tmp2) else tmp2 + 1


if n < k:
    ans = 0
    for i in range(1, n+1):
        ans += 0.5 ** calc_exponent(k, i)
    print(ans / n)
else:
    ans = 0
    for i in range(1, k):
        ans += 0.5 ** calc_exponent(k, i)
    ans = (n - k + 1) / n + ans / n
    print(ans)

Solution (Python):
import math

def main():
    n,k = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        if i+1 == k:
            ans += (n-(i+1)+1)/n
            break
        num = math.ceil(math.log(k/(i+1),2))
        ans += (1/2)**num/n
    print(ans)

if __name__ == '__main__':
    main()

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

exp = 0
tmp = 0
point= 0

for i in range(1, n + 1) :
    point = i
    tmp = 1 / n
    while point < k :
        point *= 2
        tmp /= 2
    exp += tmp

print(exp)

Solution (Python):
N, K = map(int, input().split())
P = 0
for i in range(N):
  score = i + 1
  pn = 1 / N
  while (score < K):
    pn *= 0.5
    score *= 2
  P += pn
print(P)

Solution (Python):
import math

N, K=map(int,input().split())
ansA, ansB = 0, 0
for i in range(N):
    if K/(i+1) <= 1:
        ansA += 1/N
    else:
        x = math.ceil(K/(i+1))
        y = 0.5**math.ceil(math.log2(x))
        ansB += y/N

print(ansA + ansB)

Solution (Python):
import math

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

res = 0
for i in range(N):
    now_points = i+1
    a = 1 / N
    while now_points <= K-1:
        now_points *= 2
        a /= 2
    res += a

print(res)

Solution (Python):
import math
N, K = map(int, input().split())

ans = []
for i in range(1, N+1):
    if i < K:
        ans.append(1/N * (0.5) ** (math.ceil(math.log2(K/i))))
    else:
        ans.append(1/N)
print(sum(ans))

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

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

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

    ans += (1/n)*(1/2)**cnt
print(ans)

Solution (Python):
N,K = map(int,input().split())
ans = 0

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

Solution (Python):
n, k = map(int, input().split())
pow, sum = 0, 0

for i in range(n, 0, -1):
    while i*2**pow < k:
        pow += 1
    sum += 0.5**pow

print(sum/n)

Solution (Python):
n , k = (int(x) for x in input().split())
prob = 0
power = 0
for i in range(n,0,-1):
  while i*(2**power) < k:
    power += 1
  prob += (1/n)*(1/2)**power
print(prob)

Solution (Python):
import math
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
	t=1
	ii=i
	while ii<k:
		ii*=2
		t/=2.0
	ans+=t
ans=float(ans)/n
print(ans)

Solution (Python):

import sys
import math


def solve(N: int, K: int):
    result = 0
    for i in range(1, N + 1):
        
        if i < K:
            count = math.ceil(math.log2(K / i))
            result += (1 / N) * 0.5 ** (count)
        else:
            result += 1 / N
    print(result)
    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))  
    K = int(next(tokens))  
    solve(N, K)


if __name__ == "__main__":
    main()

Solution (Python):
N, K = map(int, input().split())
p = []

for i in range(1,N+1):
  j = i
  pro = 1
  while True:
    if j >= K:
      break
    else:
      j = j*2
      pro = pro / 2
  p.append(pro)

print(sum(p)/N)

Solution (Python):
from math import log2, ceil
N,K = map(int, input().split())
result = 0
for i in range(1,N+1):
  result += 0.5 ** ceil(log2(K/i)) if i<K else 1
print(result/N)

Solution (Python):
import math
n, k = map(int, input().split())
p = 0

for i in range(1, n + 1):
    if i >= k:
        p += 1
    else:
        count = math.ceil(math.log(k / i, 2))
        p += 0.5 ** count
p /= n
print(p)

Solution (Python):
n,k=map(int,input().split())
ans=0
if n==k:
    ans+=2**20
    c=0
    for i in range(1,n):
        order=0
        c+=i
        while i<k:
            i*=2
            order+=1
        ans+=2**(20-order)
        c=0
    print(ans/(n*(2**20)))
    
    
    
elif n<k:
    c=0
    for i in range(1,n+1):
        order=0
        c+=i
        while i<k:
            i*=2
            order+=1
        ans+=2**(20-order)
        c=0
    print(ans/(n*(2**20)))
    
    
elif n>k:
    ans+=(n+1-k)*(2**20)
    c=0
    for i in range(1,k):
        order=0
        c+=i
        while i<k:
            i*=2
            order+=1
        ans+=2**(20-order)
        c=0
    print(ans/(n*(2**20) ))

Solution (Python):
import math

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

for i in range(N):
    if i+1 >= K:
        aaa += 1.0/N
    else:
        aaa += (1/N)*((1/2)**math.ceil(math.log2(K/(i+1))))
print(aaa)

Solution (Python):
n,k = map(int,input().split())
result = 0
count = 0

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

print(result)

Solution (Python):
import math

N, K = map(int, input().split())
ans_base = []

for i in range(1, N+1):
    ans_base.append(max(math.ceil(math.log(K / i, 2)), 0))

base_min = min(ans_base)
ans = 0
for j in range(N):
    ans += (1 / 2) ** (ans_base[j] - base_min)

ans *= (1 / N) * (1 / 2) ** base_min
print(ans)

Solution (Python):
import math
N, K = map(int,input().split())
rate=1/N
ans=0
for i in range(1,N+1):
    if i >= K:
        ans+=rate*(N-i+1)
        break
    else:
        cnt=0
        n=-(-math.log2(K/i)//1)
        ans+=rate*(0.5**n)
print(ans)

Solution (Python):
import math

N,K=map(int,input().split())
Ans=0
if N<K:
    for i in range(1,N+1):
        p=math.ceil(math.log(K/i,2))
        Ans+=(1/N)*(1/2)**p
else:
    for i in range(1,K):
        p=math.ceil(math.log(K/i,2))
        Ans+=(1/N)*(1/2)**p
    for i in range(K,N+1):
        Ans+=(1/N)

print(Ans)

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

P=[0]*N
for i in range(N):
  s=i+1
  k=0
  while s<K:
    s*=2
    k+=1
  P[i]=(1/N)*(1/2)**k

print(sum(P))

Solution (Python):
N,K=map(int,input().split())
ans=0.0
for i in range(N):
  X=0
  Y=i+1
  while(Y<K):
    Y*=2
    X+=1
  ans+=0.5**X
print(ans/N)

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

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


p=0
for n in range(1,N+1):
    s=1/N
    while n<K:
        n*=2
        s*=0.5
    
    p+=s
print(p)

Solution (Python):
n,k = map(int,input().split())
lose = 0
if n >= k:
    for i in range(1,k):
        x = 0
        j = i
        while j < k:
            j *= 2
            x += 1
        lose += (2**x - 1)/(n * (2**x))
else:
    for i in range(1,n+1):
        x = 0
        j = i
        while j < k:
            j *= 2
            x += 1
        lose += (2**x - 1)/(n * (2**x))
print(1 - lose)

Solution (Python):
n,k =map(int,input().split())
p=0
for score in range(1,n+1):
  q=1/n
  count=0
  while score <k:
    q=q/2
    score = score * 2
  p=p+q
print(p)

Solution (Python):
import math
N, K = map(int, input().split())
ans = 0.
rate = 1./N
for i in range(N):
  if i + 1 >= K:
    ans += rate
  else:
    ans += rate * 0.5 ** math.ceil(math.log(K / (i + 1), 2))
print(ans)

Solution (Python):


n,k = map(int,input().split())
coin_count = 0
dice_count = 0
def func(point,cointoss): 
	if point >= k: 
		return cointoss 
	return func(point*2,cointoss+1) 

for i in range(1,n+1):
	if not i >= k:
		coin_count += (1/2)**func(i,0) 
	else: 
		coin_count += 1

print(coin_count/n)

Solution (Python):
import math

n,k = map(int,input().split())
coin_count = 0
dice_count = 0
def func(point,cointoss):
	if point >= k:
		return cointoss
	return func(point*2,cointoss+1)

for i in range(1,n+1):
	if not i >= k:
		coin_count += (1/2)**func(i,0)
	else:
		coin_count += 1

print(coin_count/n)

Solution (Python):

def solve(n, k):
    p = 0
    for i in range(1, n + 1):
        q = 1
        j = i
        while j < k:
            q /= 2
            j *= 2
        p += q / n
    return p
print('%.12f' % solve(*map(int, input().split())))

Solution (Python):
N, K = [int(x) for x in input().split()]
ans = 0
for i in range(1, N+1):
    cnt = 1
    if (i >= K):
        ans += (1/N)
        continue
    tmp = i
    while(True):
        tmp *= 2
        if (tmp >= K):
            break
        cnt += 1
    ans += (1/N * (1/2 ** cnt))
print(ans)

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

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

Solution (Python):

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

ans = []
for i in range(1, N+1):
    cnt = 0
    j = i
    while j < K:
        cnt += 1
        j *= 2
    ans.append(1 / (N * (2 ** cnt)))
print(sum(ans))

Solution (Python):
import math
N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    if i < K:
        ans += (0.5 ** math.ceil(max(math.log2(K / i), 1)))
    else:
        ans += 1
print(ans / N)

Solution (Python):
import math

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

ans = 0

if N < K:
    for a in range(N):
        t = math.log2(K)-math.log2(a+1)
        i = math.ceil(t)
        ans += (1/N) * (0.5 ** i)

else:
    for a in range(N):
        if a+1 >= K:
            ans += (1/N)
        else:
            t = math.log2(K)-math.log2(a+1)
            i = math.ceil(t)
            ans += (1/N) * (0.5 ** i)

print(ans)

Solution (Python):
N,K = map(int,raw_input().split())
ans = float(0)
tmp = 0
con = 0
for i in range(1,N+1):
  tmp = i
  for j in range(0,K,i):
    if tmp >= K:
      break
    tmp = tmp * 2
    con = con + 1
  ans = ans + (1.0/2.0)**con * (1.0/N)
  con = 0
  tmp = 0
print ans

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

Prolist = []

for i in range(1,N + 1):
	Value = i
	Pro = 0
	while Value < K:
		Value = Value * 2
		Pro += 1
	Prolist.append(Pro)

total = 0

for i in Prolist:
	total += (1 / N) * 2 ** (-i)
	
print(total)

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

prob = 0
for i in range(1, n+1):
    j = 0
    tmp = 1/n
    while i*pow(2, j) < k:
        tmp /= 2
        j += 1
    prob += tmp
print(prob)

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

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

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

print(to)

Solution (Python):
n,k=map(int,input().split())
m=0
for i in range(1,n+1):
  l=k
  j=0
  while l>i:
    l/=2
    j+=1
  m+=1/n*((1/2)**j)
print(m)

Solution (Python):
import math

n, k = map(int, input().split())
count = 0
for i in range(1, n+1):
  a = max(0, math.ceil(math.log2(k/i)))
  count += 1 / (n * 2**a)
print(count)

Solution (Python):
N, K =map(int, input().split())
total = 0
for i in range(1, N + 1):
    if i >= K:
        total += 1
    else :
        coin = 0
        while i < K:
            coin += 1
            i = i * 2
        total += 2 ** (-coin)
print(total / N)

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

sum_prob = 0
for i in range(1, N+1):
    tmp = i
    count = 0
    while tmp < K:
        tmp *= 2
        count += 1
    prob = (1/N) * (0.5 ** count)
    sum_prob += prob

print(sum_prob)

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

answer = 0

for dice in range(1,N+1):
    count = 0
    point = dice
    while point < K:
        point = point*2
        count = count + 1
    answer = answer + (1/N * 0.5**count)
    
print(answer)

Solution (Python):
import math


def main():
    N, K = map(int, input().split())
    print((max(0, N - K + 1) + sum(
        max(0, N - (math.ceil(K * 0.5 ** i)) + 1) * 0.5 ** i
        - max(0, N - (math.ceil(K * 0.5 ** (i - 1))) + 1) * 0.5 ** i
        for i in range(1, int(math.log2(K)) + 1 + 1))) / N)
    return


main()

Solution (Python):
import math


def main():
    N, K = map(int, input().split())
    print((max(0, N - K + 1) + sum((
        max(0, N - (math.ceil(K * 0.5 ** i)) + 1)
        - max(0, N - (math.ceil(K * 0.5 ** (i - 1))) + 1)) * 0.5 ** i
        for i in range(1, int(math.log2(K)) + 1 + 1))) / N)
    return


main()

Solution (Python):
import math


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


main()

Solution (Python):
import math


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


main()

Solution (Python):
import math


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


main()

Solution (Python):
import math


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


main()

Solution (Python):
import math


def main():
    N, K = map(int, input().split())
    k = int(math.log2(K)) + 1
    print((max(0, N - K + 1) + sum(
        max(0, N - (math.ceil(K * (1 / 2) ** i)) + 1) * (1 / 2) ** i
        - max(0, N - (math.ceil(K * (1 / 2) ** (i - 1))) + 1) * (1 / 2) ** i
        for i in range(1, k + 1))) / N)
    return


main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

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

x = np.arange(1,N+1,dtype=np.int64)
need = np.zeros(N,dtype=np.int32)

for _ in range(20):
    target = (x <= K-1)
    x[target] <<= 1
    need[target] += 1

counter = np.bincount(need,minlength=20)
power = np.full(20,1/2,dtype=np.float64); power[0] = 1; np.cumprod(power,out=power)

answer = (counter * power).sum() / N
print(answer)

Solution (Python):
N,K=map(int,input().split())
b=0
c=0
for i in range(N):
 b=1
 j=i+1
 while j<K:
  j*=2
  b/=2
 c+=b
d=c/N
print(d)

Solution (Python):
from functools import reduce
from math import log2
from operator import mul


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    MAX_SHIFT = int(log2(K) + 1)
    print(sum(reduce(mul, (0.5
                           if i << j < K
                           else end_of_loop()
                           for j in range(MAX_SHIFT)), 1)
              for i in range(1, N + 1)) / N)
    return


main()

Solution (Python):
from functools import reduce
from math import log2
from operator import mul


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    MAX_SHIFT = int(log2(K) + 1)
    print(sum(reduce(mul, (0.5
                           if i << j < K
                           else end_of_loop()
                           for j in range(MAX_SHIFT)), 1 / N)
              for i in range(1, N + 1)))
    return


main()

Solution (Python):
N,K=map(int,input().split())
ans=0.0


for i in range(1,N+1):
    x=0

    while True:

        if K <= i*(2**x):
            ans+= (1/N)*((1/2**x))
            break

        x+=1
        
        

print(ans)

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

probability = 0
for i in range(1,n+1):
  if i < k:
  	probability+=1/(n*(2**(math.ceil(math.log2(k/i)))))
  else:
  	probability+=1/n
  
print(probability)

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

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

Solution (Python):
import math
N,K = map(int, input().split())
if K == 1:
    print(1)
else:
    P = max(0,(N-(K-1))/N)
    t = 0
    for i in range(1,min(N+1,K)):
        foo = math.log2(K/i)
        x=math.ceil(foo)
        t+=(1/2)**x
    P+=t*(1/N)
    print(P)

Solution (Python):
n, k = map(int, input().split())
reachnum = [0 for _ in range(n)]
u = 0
while 2**u < k:
    u += 1
reachnum[0] = u
sum = 1/(2**u)
for i in range(1,n):
    if (i+1) * (2 ** (reachnum[i-1] - 1)) >= k and reachnum[i-1] > 0:
        reachnum[i] = reachnum[i-1] -1
    else:
        reachnum[i] = reachnum[i-1]
    sum += 1/(2 ** reachnum[i])
print(sum/n)

Solution (Python):
from sys import stdin

n,k = [int(x) for x in stdin.readline().rstrip().split()]

point = 0
kaku = 0.0

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

Solution (Python):
from functools import reduce
from operator import mul


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    print(sum(reduce(mul, (0.5
                           if i << j < K
                           else end_of_loop()
                           for j in range(K)), 1 / N)
              for i in range(1, N + 1)))
    return


main()

Solution (Python):
from functools import reduce
from operator import mul
import math


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    print(sum(reduce(mul, (0.5
                           if i << j < K
                           else end_of_loop()
                           for j in range(int(math.log2(K))+2)), 1 / N)
              for i in range(1, N + 1)))
    return


main()

Solution (Python):
from functools import reduce
from operator import mul


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    print(sum(reduce(mul, (0.5
                           if i << j < K
                           else end_of_loop()
                           for j in range(len(bin(K)) - 2)), 1 / N)
              for i in range(1, N + 1)))
    return


main()

Solution (Python):
from functools import reduce
from operator import mul


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    print(sum(reduce(mul, (0.5
                           if i << j < K
                           else end_of_loop()
                           for j in range(K)), 1 / N)
              for i in range(1, N + 1)))
    return


main()