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


probability = 0.0

for i in range(1,N+1) :
    toss_count = 0
    point = i
    while(K > point) :
        toss_count += 1
        point = point * 2
    
    probability += 1 / (N * pow(2,toss_count))

print(probability)

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):
  if i >= k:
    ans += 1/n
  else:
    for j in range(1, 20):
      if k <= i * int(pow(2, j)):
        ans += 1/n * pow(1/2, j)
        break
print(ans)

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

print('{:.10g}'.format(p / N))

Solution (Python):
N,K=map(int,input().split())
kouho=[i for i in range(1,N+1)]
kari=[]
count = 0
j=0
while j<len(kouho):
    if kouho[j]<K:
        count+=1
        kouho[j]*=2
    else:
        kari.append(((1/2)**count)*1/N)
        j+=1
        count=0
print(sum(kari))

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

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

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

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

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

print(kaku)

Solution (Python):
n, k = map(int, input().split())
asn = 0
for i in range(1, n+1):
    for j in range(k):
        if i * (2 ** j) >= k:
            asn += 0.5**j
            break

print(asn/n)

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

for i in range(1,n+1):
    for j in range(k):
        num = j
        if i*(2**num) >= k:
            break
    ans += 0.5**num

print(ans/n)

Solution (Python):
from math import ceil, log

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

ans = 0
for i in range(1, N+1):
    val = i
    
    
    
    count = ceil(log(K/val) / log(2))
    count = 0 if count < 0 else count
    ans += 1 / (pow(2, count) * N)

print(ans)

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

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

Solution (Python):
import math

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

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

    pro2 = 0
    for i in range(1,k):
        tmp_pro = 1 / n
        x = math.log(k/i, 2)
        if x!=int(x):
            x = int(x) + 1
        elif x==int(x):
            x = int(x)
        y = (1/2)**x
        tmp_pro *= y
        pro2 += tmp_pro

    pro = pro1 + pro2

else:
    pro = 0

    for i in range(1,n+1):
        tmp_pro = 1 / n
        x = math.log(k/i, 2)
        if x!=int(x):
            x = int(x) + 1
        elif x==int(x):
            x = int(x)
        y = (1/2)**x
        tmp_pro *= y
        pro += tmp_pro

print(pro)

Solution (Python):
import numpy as np
import math
n, k = map(int, input().split())
t = 1/n
a = 0
for i in range(1, n+1):
    s = 0
    while i*2**s < k:
        s += 1
    a += t * (1/2) ** s
print(a)

Solution (Python):
import numpy as np
import math
n, k = map(int, input().split())
t = 1/n
a = 0
for i in range(1, n+1):
    if i < k:
        s = (k + i-1) // i
        t2 = math.ceil(np.log2(s))
        a += t*((1/2) ** t2)
    else: a += t
print(a)

Solution (Python):
w=input().strip().split()

N=int(w[0])
K=int(w[1])
s=0
for i in range (N):
  j=i+1
  a=1
  while j<=K-1:
    j*=2
    a*=0.5
  s+=a/N
  
print(s)

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

def f(x,y):
    count = 0
    while (x < y):
        x = 2*x
        count += 1
    return count

for i in range(N):
    b = int(f(i+1,K))
    per += (1/N)*((1/2)**b)
print(per)

Solution (Python):
def main():
  
  n,k=map(int,input().split())
  ans=[]
  for i in range(1,n+1):
    count=0
    while(i<k):
      i=i*2
      count+=1
    ans+=[1/2**count]
  
  s=sum(ans)/n
  print(s)
  
if __name__=="__main__":
  main()

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

count = [1] * (10**5+1)

low = 1
high = k

while high - low != 0:
    for i in range(low,high):
        count[i] /= 2
    high = -(-high//2)

print(sum(count[1:n+1])/n)

Solution (Python):
import math
N,K=map(int,input().split())
ans=[]
for st in range(1,N+1):
    if st<=K:
        x =math.ceil((math.log(K/st,2)))
    else:
        x=0
    ans.append((1/2)**x)
print(sum(ans)/N)

Solution (Python):
import math

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

    ans = 0.0

    for i in range(1,n+1):
        p = 1 / n
        while i < k:
            i *= 2
            p /= 2
        ans += p
    print("{:.10f}".format(ans))

if __name__ == "__main__":
    main()

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

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

ans = 0
for i in range(1, n+1):
    p = 1 / n
    point = i
    while True:
        if point >= k:
            break
        else:
            point *= 2
            p *= 0.5
    ans += p
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 *= 2
        c += 1
    ans += 1/N/pow(2, c)
print(ans)

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

def check(i,K):
    w = 0
    score = i
    while score < K:
        w += 1
        score = score * 2
    
    return w

output = []
x = 1 / 2    


for i in range(1, N + 1):
    dice = i
    output.append(x**(check(dice,K)))

    

print((1 / N) * sum(output))

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

csum = 0
for i in range(1,N+1):
    c = 0
    flag = 1
    while flag:
        if i*2**c >= K:
            csum += 1/2**c
            flag = 0
        else:
            c += 1
print(csum/N)

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

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

prob = [1/n] * n

for i in range(n):
    score = i+1
    while(score < k):
        score *= 2
        prob[i] *= 1/2

ans = sum(prob)
print(ans)

Solution (Python):
n,k = map(int,input().split())
p = 1/n
ans = [0 for i in range(n)]
for i in range(n):
    tensu = i+1
    cnt = 0
    while k>tensu:
        tensu *=2
        cnt+=1
    saikoro = 0.5**cnt
    ans[i] = p*saikoro
print(sum(ans))

Solution (Python):
from math import ceil, log2
n, k = map(int, input().split())
X = (ceil(log2(k / (i+1))) if ceil(log2(k / (i+1))) > 0 else 0 for i in range(n))
print(sum(0.5 ** x / n for x in X))

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

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

print(ans)

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

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

    ans = 0

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

if __name__ == '__main__':
    main()

Solution (Python):
n,k = map(int,input().split())
num =0
count = 0
for i in reversed(range(1,n+1)):
    
    i1 = i
    if k > i*(2**count):
        i = i*(2**count)
        while k > i:
            i *= 2
            count += 1
    num += ((1/2)**count)*(1/n)
print(num)

Solution (Python):
N,K = map(int,input().split())
sum=0.0
for a in range(1,N+1):
    i=a
    b=1.0
    while i<K:
        i=i*2
        b=b/2
    sum+=b
print(sum/N)

Solution (Python):
from math import log2, ceil

n, k = [int(s) for s in input().rstrip().split(" ")]

s = 0

for i in range(1, n + 1):
    s += (1 / n) * ((1 / 2) ** max(0.0, ceil(log2(k / i))))

print(s)

Solution (Python):
n, k = [int(s) for s in input().rstrip().split(" ")]

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

s = 0

for i in range(1, n + 1):
    s += (1 / n) * ((1 / 2) ** f(i, k))

print(s)

Solution (Python):
from math import ceil, log2

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

ans = 0
d = {}
d[0] = 1
for i in range(n, 0, -1):
    c = ceil(log2(k / i))
    if c < 0:
        c = 0
    if c not in d:
        d[c] = pow(1/2, c)
    ans += d[c] / n

print(ans)

Solution (Python):
n, k = map(int, input().split())
a = []
for i in range(1,n+1):
    for j in range(0, 100000):
        if k <= i*2**j:
            a.append(1/n * (0.5**j))
            break
print(sum(a))

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

Solution (Python):
import math

N, K = map(int, input().split())
ans = 0
if N <= K:
    for n in range(1, N+1):
        ans += (1/N) * (1/2)**math.ceil(math.log2(K/n))
elif N > K:
    for n in range(1, K+1):
        ans += (1/N) * (1/2)**math.ceil(math.log2(K/n))
    ans += (1/N) * (N - (K+1) + 1)
print(ans)

Solution (Python):
import math as mt
N,K = [int(i) for i in input().rstrip().split()]
R = 0
for n in range(1,N+1):
    l = mt.floor(mt.log2(K/n) - 0.1**9)+1
    if l <= 0:
        R += 1/N*(N-n+1)
        
        break
    else:
        R += 1/N*0.5**l
        
print(R)

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

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

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

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

Solution (Python):
from math import log2  as log
n,k=map(int,input().split())
ans=max(n-k+1,0)/n
for i in range(1,min(n+1,k)):
  ans+=1/(n*(2**(-(-log(k/i)//1))))
print(ans)

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

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

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

sum = 0
cnt = 0

for i in range(1,a+1):
  cnt = 0
  while i < b:
    i *= 2
    cnt += 1
  sum += 1/a*(0.5)**cnt
print(sum)

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

def n(x, n):
    return x * 2**(n-1)

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

Solution (Python):
import math

def calc_omote(x, y):
    score = x
    omo = 0
    while(score < y):
        score *= 2
        omo += 1
    return omo
        

n, k = map(int, input().split())
ans = 0
for i in range(1,n+1):
    omote = calc_omote(i, k)
    p = 1/(2**omote)
    ans += p/n

print(ans)

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

dice = 1/n

ans = 0

for i in range(1,n+1):
    buf = math.ceil((math.log(k/i,2)))
    if buf < 0:
        buf = 0
    ans += dice * (1/2) ** buf

print(ans)

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

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

print(ans)

Solution (Python):


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

class Result:
    def __init__(self, win, lose):
        self.win = win
        self.lose = lose
        self.total = win + lose


dic = {}

def getAns(num:int):
    if num >= k:
        return Result(1, 0)
    if num in dic:
        return dic[num]
    r = getAns(num*2)
    ret = Result(r.win, r.lose + r.total)
    dic[num] = ret
    return ret


result_list = [getAns(i) for i in range(1, n + 1)]
max_total = max([i.total for i in result_list])
total = max_total * len(result_list)
win_total = sum([i.win * (max_total/i.total) for i in result_list])
print(win_total/total)

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

Solution (Python):
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    N, K = MAP()

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

    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
import math

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


sum_v = 0

if n >= k :
    j = k
    s = [0]*(k-1)
else:
    j = n + 1
    s = [0]*n
    
for i in range(1, j):
    s[i-1] = math.ceil(math.log2(k/i))
    sum_v += (1/2)**s[i-1]
    
    
if n - k >= 0: 
    p1 = (n-k+1)/n
else:
    p1 = 0
    
p2 = sum_v/n
print(p1 + p2)

Solution (Python):
import numpy as np

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

nx = np.arange(1, n+1)

ans = 0
ed = n
coin = 0

while (ed > 0):
    ct = 0
    for i in range(ed-1, -1, -1):
        if (nx[i] >= k):
            ct += 1
            ed = i
        else:
            break
    ans += ct*(1/2**(coin))

    
    nx *= 2
    coin += 1

print(ans/n)

Solution (Python):
N,K = map(int,input().split())
ans = 0
for n in range(1,N+1):
    if n >= K:
        ans += 1
        continue
    k = 0
    m = n
    while m < K:
        m *= 2
        k += 1
    ans += 2**-k
print(ans/N)

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

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

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

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

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

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

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

print(ans)

Solution (Python):
n, k = 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):
nums = input().split()
N = int(nums[0])
K = int(nums[1])
totalProb = 0

for i in range(N):
    x = i + 1
    tempProb = 1/N

    while x < K:
        tempProb = tempProb / 2
        x = x * 2

    totalProb += tempProb

print(totalProb)

Solution (Python):
def win_cou(n,m):
    cou = 0
    while m > n:
        n = n * 2
        cou = cou + 1
    return cou



Input = input().split()
N = int(Input[0])
K = int(Input[1])
rate = 0

for i in range(N):
    rate = rate + 2 ** (win_cou(i+1,K)*(-1)) / N

print(rate)

Solution (Python):
def win_cou(n,m):
    cou = 0
    while m > n:
        n = n * 2
        cou = cou + 1
    return cou*(-1)



Input = input().split()
N = int(Input[0])
K = int(Input[1])
rate = 0

for i in range(N):
    rate = rate + (2 ** win_cou(i+1,K)) / N

print(rate)

Solution (Python):
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
    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())
from math import log,ceil

if n>=k:
  ans=n-k
else:
  ans=0
for i in range(1,min(n,k)+1):
  ans+=1/(2**ceil(log(k/i,2)))
ans/=n
print(ans)

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

if n < k:
    res = 0
else:
    res = n - k
for i in range(1, min(n, k) + 1):
    pow2 = math.ceil(math.log(k / i, 2))
    res += 0.5 ** pow2
print(res / n)

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

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

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

ans = 0
i = 1
cnt = 0
c = N
while c != 0:
    if c * i >= K:
        ans += 1 / ((2 ** cnt) * N)
        c -= 1
    else:
        i *= 2
        cnt += 1

print(ans)

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

ret = 0
for i in range(1, n+1):
   tmp = 1.0 / n
   now = i

   while(now < k):
      now *= 2
      tmp /= 2

   ret += tmp

print(ret)

Solution (Python):

n,k = map(int,input().split())
ans_prob = 0
beki_cnt = 0
for i in range(n,0,-1):
    while True:
        
        if i >= k / (2** beki_cnt): 
            ans_prob += 1/ ((2**beki_cnt) * n)
            
            
            break
        else:   beki_cnt += 1
print(ans_prob)

Solution (Python):

n,k = map(int,input().split())
ans_prob = 0
beki_cnt = 1
for i in range(n,0,-1):
    if i >= k: ans_prob += 1/n
    else:
        while True:
            
            if i >= k / (2** beki_cnt): 
                ans_prob += 1/ ((2**beki_cnt) * n)
                
                
                break
            else:   beki_cnt += 1
print(ans_prob)

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

for i in range(1, N+1):
    x = 0
    num = i * 2 ** x
    
    while (K > num):
        x += 1
        num = i * 2 ** x        
        
    prob += 1 / N * (1 / 2) ** x

print(prob)

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

Solution (Python):
import sys
from math import log2, ceil

n, k = map(int, sys.stdin.readline().split())

def main():
    res = 0
    for i in range(1, n+1):
        if i >= k:
            res += n - i + 1
            break
        res += pow(2, -ceil(log2(k / i)))

    return res / n

if __name__ == '__main__':
    ans = main()
    print(ans)

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

ans = 0
for i in range(1, N+1):
  cnt = 0
  point = i
  while point < K:
    point *= 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):
    count = 0
    point = i
    while point < k:
        point *= 2
        count += 1

    ans += 1 / n * (0.5 ** count)

print(ans)

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

for n in range(1, N+1):
  if n >= K:
    break

  count = 0
  t = n
  while(t < K):
    t = t * 2
    count += 1
    
  k += (1 / N) * (1 - (1 / 2) ** count)

print(1 - k)

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

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

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

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

sum = 0

for i in range(1, n+1):
    cnt = 0
    while(1):
        if i < k:
            cnt += 1
            i = i * 2
        else:
            break
    sum = sum + (1/n) * (1/2)**cnt

print(sum)

Solution (Python):

def coin(a,k):
    point = a
    c=0
    while point<k:
        point  *= 2
        c += 1
    return c
def main():
    n,k=map(int,input().split())
    print(sum([1/(n*2**coin(i,k)) if i<=k else 1/n for i in range(1,n+1)]))    
main()

Solution (Python):
N, K = map(int, input().split())
cnt_list = []
cnt_value = 0
for i in range(1, N+1):
    cnt = 1
    cnt_value = i
    while (1):
        if K <= cnt_value:
            cnt_list.append(cnt)
            break
        cnt_value *= 2
        cnt += 1
for i in range(len(cnt_list)):
    cnt_list[i] = float(1/(2**(cnt_list[i]-1)))

print("{0:.16f}".format(float(sum(cnt_list)/N)))

Solution (Python):

def resolve():
    import sys
    input = sys.stdin.readline
    
    N, K = map(int, input().split())

    def get_trynum(X, K):
        count = 0
        while X < K:
            X *= 2
            count += 1
        return count

    win_rate_total = 0
    for i in range(1, N+1):
        try_num = get_trynum(i, K)
        win_rate = 0.5 ** try_num 
        win_rate_total += win_rate * (1/N)
    
    print(win_rate_total)

if __name__ == "__main__":
    resolve()

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, K: int):
    def rec(n: int):
        if n >= K:
            return 0
        return rec(n*2)+1
    
    ans = 0
    for i in range(1, N+1):
        ans += 1/N * pow(1/2, rec(i))
    print(ans)
    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 = 1/n

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

print(ans)

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

p=0.0
for i in range(1,n+1):
    m=0

    while k>i*2**m:

        m=m+1

    p=p+(0.5)**m/n
print(p)

Solution (Python):


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

def border(n, k):
    cnt = 0
    while True:
        if n*2**cnt >= k:
            return cnt
        else:
            cnt += 1

ans = 0
for i in range(1, n+1):
    ans += 1/n * 0.5 ** border(i, k)

print(ans)

Solution (Python):
N , K = (map(int , input().split()))
ans_list = []
for i in range(1,N+1):
    ss = i
    count = 0
    while ss < K:
        ss = ss * 2
        count += 1
    ans_list.append((1/N)*((1/2)**count))
print(float(sum(ans_list)))

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



def calc_multi(k, x):
    cnt = 0
    while x < k:
        cnt += 1
        x *= 2
    return cnt


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

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

bin_k=format(K,'b')
bin_len_k=len(bin_k)

def f(x):
    bin_x=format(x,'b')
    sa=bin_len_k-len(bin_x)
    if sa<1: sa=0

    bin_x_=bin_x+'0'*sa
    if int(bin_x_,2)<int(bin_k,2):
        return sa+1
    else:
        return sa

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


print(ans)

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

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

print(ans/n)

Solution (Python):
import math                                                                                                                                                         
                                                                                                                                                                    
def ci(n,k):                                                                                                                                                        
    
    a = n-k+1                                                                                                                                                       
    if(a<0):                                                                                                                                                        
        return 0                                                                                                                                                    
    else:                                                                                                                                                           
        return float(a/n)                                                                                                                                           
                                                                                                                                                                    
def coin(n,k):                                                                                                                                                      
    a = k/n                                                                                                                                                         
    if(a<1):                                                                                                                                                        
        return 0                                                                                                                                                    
    else:                                                                                                                                                           
        m = math.log(a)/math.log(2)                                                                                                                                 
        
        
        return(int(math.ceil(m)))                                                                                                                                   
                                                                                                                                                                    
def p_coin(n):                                                                                                                                                      
    return math.pow(0.5, n)                                                                                                                                         
                                                                                                                                                                    
def sumP3(n,k):                                                                                                                                                     
    a = 0                                                                                                                                                           
    for i in range(1, k):                                                                                                                                           
        if i>n :                                                                                                                                                    
            break                                                                                                                                                   
        
        
        a = a + (1/N[0])*p_coin(coin(i,k))                                                                                                                          
    return a                                                                                                                                                        
                                                                                                                                                                    
N = input().split()                                                                                                                                                 
N = [int(i) for i in N]                                                                                                                                             


p1 = ci(N[0], N[1])                                                                                                                                                 
p2 = 1-p1                                                                                                                                                           
p3 = sumP3(N[0], N[1])                                                                                                                                              
print('{:.10g}'.format(p1+p3))