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):

def turn(a,x):
	b = 0
	while a < x:
		b += 1
		a *= 2
	return b

n, k = [ int(v) for v in input().split() ]
anslist = [ 2**(-turn(i+1,k)) for i in range(n) ]


print(sum(anslist)/n)

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

Solution (Python):
import math

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

l = []
for i in range(n):
    if i <= k:
        m = math.ceil(math.log2(k/(i+1)))
        l.append(1/2**m)
    else:
        l.append(1)

print(1/n*sum(l))

Solution (Python):
import math
def main():
    n,k = [int(i) for i in input().split()]
    ans = 0.0
    for i in range(1, n+1):
        
        if k <= i:
            
            ans += 1/n
        else:
            
            ans += 1/n*(1/2)**math.ceil(math.log2(k/i))
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import math

def solve():
	diceSurfaces, winBorder = [int(x) for x in input().split()]
	diceProbability = (1 / diceSurfaces)
	ans = 0
	for score in range(1, diceSurfaces + 1):
		if score >= winBorder:
			ans += diceProbability
			continue 
		needNum  = math.ceil((winBorder) / score)
		needWins = math.ceil(math.log2(needNum))
		ans += diceProbability * ((1/2) ** needWins)
	print(ans)
solve()

Solution (Python):
from math import ceil, log2

n, k = map(int, input().split())
a = sum((2 ** (-ceil(log2(k / i)))) / n for i in range(1, min(k, n + 1)))
b = (n - k + 1) / n if n >= k else 0
print(a + b)

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

for s in range(1,N+1):
    j = 1/N
    while s<K:
        s *= 2
        j /= 2
    out += j

print(out)

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

probs = []
for i in range(1, N+1):
    
    a = i
    n = 0
    while a < K:
        a *= 2
        n += 1

    p = (1/N) * (1/2)**n
    probs.append(p)

print(sum(probs))

Solution (Python):
n,k = map(int,input().split())
if n >= k:
    answer = (n-k+1)/n
else:
    answer = 0.0

for i in range(1,min(n+1,k)):
    j = 1
    while True:
        if i*(2**j) >= k:
            answer += (0.5**j)/n
            break
        else:
            j += 1

print(answer)

Solution (Python):


def main():
	n, k = map(int, input().split())
	win_per = 0
	for i in range(n):
		count = 0
		score = i + 1
		if score <= k:
			while True:
				if score >= k:
					break
				score *= 2
				count += 1
			win_per += (1 / n) * (1 / 2)**count
		else:
			win_per += 1 / n
	print(win_per)

if __name__ == "__main__":
	main()

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

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

a=k
b=n
count=0
halfcount=0
while(k>0.5):
    if b>=k and k%1==0:
        count+=(b-int(k)+1)/(2**halfcount)/n
        b=int(k)-1
    elif b>=k:
        count+=(b-int(k))/(2**halfcount)/n
        b=int(k)
    halfcount+=1
    k/=2




print(count)

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

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


print(ans/N)

Solution (Python):
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)

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

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

  ans += workp
  
print(ans)

Solution (Python):
import math

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

ans = 0

for i in range(1, n+1):
    if i >= k:
        ans += 1/n

    else :
        coin = math.ceil(math.log2(k/i))
        ans += (1/n)*(1/2)**(coin)


print(ans)

Solution (Python):
def get_n(k, K):
    ruijo = k

    if k >= K:
        return 0

    for i in range(1, 1000000):
        ruijo = ruijo * 2
        if ruijo >= K:
            return i

    return -1


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

p = 0

for i in range(1, N+1):
    tmp = float(1/N) * float(1/2)**(int(get_n(i, K)))
    p = p + tmp

print(p)

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

import math

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

Solution (Python):
import math

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

ans = float(0)
logK = math.log(K, 2)

for n in range(1, N + 1):
    if n >= K:
        ans = ans + float(1 / N)
    else:
        prob_n = 1.0 / math.pow(2, math.ceil(logK - math.log(n, 2)))
        ans = ans + float(1 / N * prob_n)

print(ans)

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

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

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

Solution (Python):
import numpy as np
N,K = map(int,input().split())
ans =1
p=0
for num in range(1,N+1):
    tmp = 1/N
    now = num
    while now < K:
        now *= 2
        tmp /= 2
    p += tmp
print(p)

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())



import math
N, K = mi()


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

print(ans / N)

Solution (Python):
from math import log2,ceil
p = 0
dice, point = map(int,input().split())
for i in range(1,dice+1):
  temp = ceil(log2(point/i))
  if temp < 0:
    temp = 0
  p += (1/2) ** temp / dice
print(p)

Solution (Python):
from math import log2, ceil

n, k = [int(i) for i in input().split()]

a = 0
for i in range(1, n + 1):
    b = max(ceil(log2(k/i)), 0)
    a += (1 / 2 ** b) / n
print(a)

Solution (Python):

n1, n2 = [int(i) for i in input().split()]

s1  = float(0)
for i1 in range(n1):
    r1 = (i1 + 1)
    c1 = 1
    if n2 <= r1:
        s1 += (1/n1)
        continue

    while True:
        r1 *= 2
        c1 = c1 * (1/2)
        if n2 <= r1:
            s1 += ((1/n1)*c1)
            break

print('{:.12g}'.format(s1))

Solution (Python):
N,K = map(int,input().split())
bosu = [N]*N
for i in range(1,N+1):
    point = i
    while point < K:
        point *= 2
        bosu[i-1] *= 2
        
ans = 0
for i in bosu:
    ans += 1/i

print(ans)

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

Solution (Python):
import math
N,K = map(int,input().split())
List = []
for i in range(1,N+1):
    if i>=K:
        List.append(0)
    else:
        tmp = i
        count = 0
        while(tmp<K):
            tmp = tmp*2
            count+=1
        List.append(count) 
        
ans = [0]*N
ans[0] = 0.5**List[0]/N
for i in range(1,N):
    if List[i-1]==List[i]:
        ans[i] = ans[i-1]
    else:
        ans[i] = (2**(List[i-1]-List[i]))*ans[i-1]
print(sum(ans))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  N,K=LI()
  a=1/N

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

    ans+=1/c

  return ans*a

print(main())

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

Solution (Python):
import math

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

probability_list = []

for i in range(N):
    if i+1 > K:
        probability_list.append(float(1))
    else:
        probability_list.append(1/2**(math.ceil(math.log2(K/(i+1)))))

print(sum(probability_list)/N)

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

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

print(ans)

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

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

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

for n in range(N):
    k=0
    while n<=K-2:
        n=2*(n+1)-1
        k+=1
    ans+=1/2**k
        
print(ans/N)

Solution (Python):
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
P = 0
for i in range(1, N + 1):
    if i > K:
        continue
    e = 0
    while i * 2 ** e < K:
        P += 1 / N * 0.5 ** (e + 1)
        e += 1
print(1 - P)

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

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

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

print(tmp/N)

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

Solution (Python):
import math
def resolve():
    (N, K) = list(map(int, input().split(" ")))
    ans = 0
    for n in range(1, N+1):
        ans = ans + (1/N) * pow(2, -1*(max(0, math.ceil(math.log2(K/n)))))
    print(ans)

if '__main__' == __name__:
    resolve()

Solution (Python):


import math

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

prob = 0
for i in range(1,n + 1):
    if i >= k:
        prob += 1/n
    else:
        ratio = math.ceil(math.log2(k / i))
        prob += (1/n) * ((1/2) ** ratio)

print(prob)

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

Solution (Python):
n, k = map(int, input().split())
ans = 0
for i in range(1,n+1):
	ans_temp = 1/n
	for j in range(1000):

		if i >= k:
			ans += ans_temp
			break
		else:
			i = i * 2
			ans_temp = ans_temp/2
print(ans)

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

cur_coin_count = 0
cur_probability = 1

tmp = N
while True:
    if tmp >= K:
        break
    tmp *= 2
    cur_coin_count += 1
    cur_probability /= 2
ret = cur_probability

num = N-1
while num > 0:
    if num * (2 ** cur_coin_count) < K:
        cur_coin_count += 1
        cur_probability /= 2

    ret += cur_probability
    num -= 1
ret /= N
print(ret)

Solution (Python):
import math
import fractions
import copy

def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)



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










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

Solution (Python):
import sys

def step_count(val, lim):
    count = 0
    while True:
        if val >= lim:
            return count
        else:
            val *= 2
            count += 1

def main():
    sinputl = sys.stdin.readline

    dice, limit = [int(x) for x in sinputl().split()]

    chance = 0.0

    for first in range(1, dice+1):
        chance += (1/dice) * (1/ 2 ** step_count(first, limit))

    print(chance)



if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin

import math

N, K = stdin.readline().rstrip().split()
N = int(N)
K = int(K)
if K <= 1:
    print(1)
    exit(0)


print(sum([(1/2)**(math.floor(math.log(((K-1)/n), 2))+1) if n < K else 1 for n in range(1, N+1)]) / N)

Solution (Python):
import math
n, k = [int(v) for v in input().split()]






pi = []
for i in range(1,n+1):
  if i < k:
    ai = math.ceil(math.log(k/i, 2))
    pi.append( ((1/2)**ai) / n )
  else:
    pi.append( 1 / n )
    
print(sum(pi))

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

Solution (Python):
N,K=map(int,input().split())
ans=0
for n in range(1,N+1):
	p=0
	while n*2**p<K:
		p+=1
	ans+=(0.5**p)/N
print('{:.12f}'.format(ans))

Solution (Python):
def calc(x):
    count=0
    while x <K:
        count+=1
        x*=2
    return count
    
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
    num=calc(i)
    ans+=1/N*((1/2)**num)
print(ans)

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

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

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

tN = N
tK = K
tP = 1
ans = 0

for i in range(20):
    
    if tN >= tK:
        if tK > int(tK):
            ans += ((tN -int(tK)) * tP)/N
            tN = int(tK)
        else:
            ans += ((tN -int(tK)+1) * tP)/N
            tN = int(tK)-1
        
    tP = tP/2
    tK = tK/2
print(ans)

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

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

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

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

ans = 0
for i in range(1,n+1):
  tmp = math.floor(k/i)
  if tmp == 0:
    ans += 1/n
  elif k % i == 0 and tmp & tmp-1 == 0:
    ans += 1/(n*(2**(len(bin(tmp))-3)))
  else:
    ans += 1/(n*(2**(len(bin(tmp))-2)))
print(ans)

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

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

print(ans / N)

Solution (Python):

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

Solution (Python):
import math

n, k = [int(i) for i in input().split()]









p = 0.0

for i in range(n):
    j = i + 1
    if (j < k) :
        p += 2 ** ( - math.ceil( math.log2(k / j) ) )
    else :
        p += 1
p = p / n

print(p)

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

sum_prob = 0
for i in range(1,N+1):
  curr_score = i
  coin_heads = 0
  while curr_score < K:
    curr_score = curr_score * 2
    coin_heads += 1
  sum_prob += 1./N * (0.5)**coin_heads

print(sum_prob)

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

prob = 0.0
potencias = [1]
i = 1
while i < 100001:
    i *= 2
    potencias.append(i)



for i in xrange(1, N+1):
    if i < K:
        j = 0
        while potencias[j]*i < K:
            j += 1
        p = 1.0/(N*1.0)
        p *= (0.5**j)
        prob += p
    else:
        prob += 1.0/(N*1.0)
    
print prob

Solution (Python):
N, K = map(int, input().split())
p = 0.0
for i in range(1, (N+1)):
    tmp = 1/N
    x = i
    while x < K:
        x *= 2
        tmp /= 2
    p += tmp
print(p)

Solution (Python):
N, K = map(int, input().split())
p = 0.0
for i in range(1, (N+1)):
    tmp = 1/N
    x = i
    while x < K:
        x *= 2
        tmp /= 2
    p += tmp
print(p)

Solution (Python):
n,k = map(int,input().split())
kli = [k]
kch = k
while True:
  if kch == 1:
    break
  kch = (kch-1)//2 + 1
  kli.append(kch)
kli.reverse()
qli = []
def f(x):
  if x > 0:
    return x
  else:
    return 0
le = len(kli)
for i in range(le-1):
  p = min(n+1,kli[i+1])
  q = p - kli[i]
  qli.append(f(q))
qli.append(f(n+1-kli[-1]))
qli.reverse()
b = 1
son = 0
for i in range(le):
  son += b * qli[i]
  b /= 2
print(son/n)

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

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

prob = 0
for now_ in range(1, N+1):
  times = 0
  if now_ >= K:
    prob += (1/N) * (N - now_ + 1)
    break
    
  while K > now_:
    now_ *= 2
    times += 1
  prob += (1/N) * (1/2)**times
print(prob)

Solution (Python):
n,k=map(int,input().split())
p=0
if n >= k:
    p+=(n-k+1)/n


a=n+1 if n<k else k
for i in range(1,a):
    p_tmp=(1/n)
    j=i
    while j<k:
        p_tmp*=0.5
        j*=2
    p+=p_tmp

print(p)

Solution (Python):
N, K = [int(i) for i in input().split()]
import numpy as np
ans = []
for i in range(N):
    score = i + 1
    counter = 0
    while score <= K - 1:
        score = score * 2
        counter += 1
    ans.append((1/N)*((1/2)**counter))
print(np.sum(ans))

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

Solution (Python):
n, k = map(int, input().split())
cnt = 0
prob = 0
score = 0
for i in range(1, min(n+1,k)):
        score = i
        while True:
                score = score*2
                cnt += 1
                if score >= k:
                        break
        prob += 1/n * (1/2)**(cnt)
        cnt = 0
if n >= k:
        ans = (prob + (n-k+1)/n)
else:
        
        ans = prob
print(ans)

Solution (Python):
import math
n,k=map(int, input().split())
ans=0
for i in range(1,n+1):
    temp = math.log2(k)-math.log2(i)
    if temp<0:
        ans+=1/n
    else:
        ite = math.ceil((math.log2(k)-math.log2(i))/math.log2(2))
        ans+=pow(0.5,ite)/n
print(ans)

Solution (Python):
import numpy as np
n, k = map(int, input().split())
print(sum(min(1, 2 ** (-np.ceil(np.log2(k / i)))) for i in range(1, n + 1)) * (1 / n))

Solution (Python):
import numpy as np
n, k = map(int, input().split())

p = 1 / n
result = 0
for i in range(1, n + 1):
    result += min(1, 2 ** (-np.ceil(np.log2(k / i))))
print(p * result)

Solution (Python):
n,k = map(int,input().split())
count = 0
def sai(a,b):
    p = 0
    while a < b:
        a = a*2
        p = p + 1
    return p
for i in range(n):
    count = count + float((1/n)*(1/(2**(sai(i+1,k)))))
print(count)

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

sum = 0

for i in range(1,n+1):
    sc = i
    pr = 1/n
    while sc < k:
        sc *= 2
        pr *= 1/2
    sum += pr

print(sum)

Solution (Python):
import math

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

for i in range(1, min(N+1, K)):
  p += 1 / 2 ** (math.ceil(math.log(K/i, 2)))

print((p + max(N-K+1, 0)) / N)

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

ans=0
for i in range(1,N+1):
    n=K/i
    p=0
    while n>1:
        n/=2
        p+=1
    if p==0: ans+=1
    else: ans+=1/(2**p)
    

print(ans/N)

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

Solution (Python):

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

s=0

for i in range(1,n+1):
    
    x=1/n
    j=i
    while(j<k):
        j*=2
        x/=2
    s+=x
print(s)

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

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

def expo(i, k):
    count = 0
    while i<k:
        i *= 2
        count+=1
    return count

for i in range(1, min(n+1, k)):
    exp = expo(i, k)
    ans += (1/n * (1/2)**exp)

if n >= k:
    ans += ((n - (k-1)) / n)
    
print(ans)

Solution (Python):
import math

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

count = 0
now = K

while now > N :
    count += 1
    now = now / 2.

prob = 0

for i in range(1,N+1) :
    if i < now :
        for k in range(N) :
            if i * 2**k >= now :
                break
        prob += 2**(-(count + k )) / N
    else :
        prob += 2**(-count) / N

print(prob)

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

Solution (Python):
def getindex(i):
    for a in range(K+1):
        if i*2**a >= K:
            return a

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

for i in range(1,N+1):
    x = getindex(i) if i < K else 0
    pulas = (1/N)*((0.5)**x) if x > 0 else 1/N
    result += pulas

print(result)

Solution (Python):
def kakeru(i):
    for a in range(K+1):
        if i*2**a >= K:
            return a

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

for i in range(1,N+1):
    x = kakeru(i) if i < K else 0
    pulas = (1/N)*((0.5)**x) if x > 0 else 1/N
    result += pulas

print(result)

Solution (Python):
def kakeru(i):
    for a in range(K+1):
        if i*2**a >= K:
            
            
            return a


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

for i in range(1,N+1):
    x = kakeru(i) if i < K else 0
    
    pulas = (1/N)*((0.5)**x) if x > 0 else 1/N
    result += pulas
    

print(result)

Solution (Python):

import math

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

A = [max(math.ceil(math.log2((K)/(i+1))), 0) for i in range(N)]
A = [1/(2**a) for a in A]

print(sum(A)/len(A))

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

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    
    ans = 0
    for i in range(N):
        coin = 1 / N
        bai = i + 1
        
        while bai < K:
            bai = bai * 2
            coin = coin / 2
        
        ans = ans + coin
    
    print(ans)

if __name__ == '__main__':
    main()

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

ans=0

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

print(ans)

Solution (Python):

def count(N,K):
    a=0
    while K>N:
        N=N*2
        a=a+1
    return a




N,K=input().split()
N=int(N)
K=int(K)
a=[0]*N
for num in range(0,N):
    a[num]=num+1
ans=0
for num in range(0,N):
    ans=ans+pow(0.5,count(a[num],K))
print(ans/N)

Solution (Python):
import math


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

ans = 0

for n in range(1, N+1):
    
    
    
    num_success = max(0, math.ceil(math.log2(K/n)))
    ans += (1/2) ** num_success

print(ans/N)

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

Solution (Python):

N,K = input().split()

N = int(N)
K = int(K)

ans = 0.0

for i in range(N):
    dice = i + 1
    point = dice

    now_prob = 1/N

    while point < K:

        point *= 2
        now_prob *= 0.5

    ans += now_prob

print (ans)

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


def getP(p, i):
    if i*2 < K:
        return getP(p+1, i*2)
    else:
        return p+1

ans = 0
for i in range(1, N+1):
    if i >= K:
        ans += 1 / N
    else:
        ans += 0.5 ** getP(0, i) / N

print(ans)

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

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

ans = 0
for i in range(1, N+1):
    J = i
    t = 0
    while K > J:
        J = J * 2
        t += 1
        
    ans += (1 / N) * 0.5**t 
    
print(ans)

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

res = 0
for value in range(1, n + 1):
    if value >= k:
        res += (1 / n)
    else:
        
        tmp = 0
        while value * 2 ** (tmp) < k:
            tmp += 1
        res += (1 / n * (1 / 2) ** tmp)
print(res)

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

import math
x=0

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

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

prob_list = [2 ** -(math.ceil(math.log(K / n, 2))) if n < K else 1 for n in range(1, N + 1)]
prob = sum(prob_list) / N
print(prob)

Solution (Python):
n, k = map(int, input().split())
ans = 0
for i in range(1, n+1):
    cur = i
    count = 0
    while True:
        if cur >= k:
            break
        cur *= 2
        count += 1
    
    ans += (0.5 ** count) / n

print(ans)

Solution (Python):

"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""


"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""
import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect


def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())


dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')


ABT = zip(A, B, totAB)
result = 0

sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)


(x >> i) & 1


dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

add = 1 
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)


li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    


org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)




    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""
N, K = list(map(int, input().split()))
def main():
    p = 0.
    if K <= N:
        p += float(N-K+1)/float(N)
    if K<=N:
        r = K
    else:
        r = N+1
    for n in range(1,r):
        i = 1         
        while n*2**i<K:
            i+=1
        p += 1./float(N)*(1./2.)**(float(i)) 
            
    print(p)
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

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

prob_sum = 0

for i in range(N + 1)[1::]:
    current = i
    prob = 1
    while(True):
        if(K <= current):
            break
        prob = prob * 0.5
        current = current * 2
    prob_sum += prob

print(prob_sum / N)

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

ls = []

def multiply(ls):
    result = []
    for i in range(len(ls)):
        result.append(pow(N, -1) * ls[i])
    return result

if N < K:
    for i in range(1, N + 1):
        p = i
        cnt = 0
        while p < K:
            p *= 2
            cnt += 1
        ls.append(pow(2, -cnt))
    print(sum(multiply(ls)))
else:
    for i in range(1, K):
        p = i
        cnt = 0
        while p < K:
            p *= 2
            cnt += 1
        ls.append(pow(2, -cnt))
    print(sum(multiply(ls)) + (N - K + 1) / N)

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

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