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 pows(n, K):
    count = 0
    while True:
        if n >= K:
            return count
        n = n * 2
        count += 1


def main():
    N, K = list(map(int, input().split()))
    
    re = 0
    
    for i in range(1, N + 1):
        if i >= K :
            re = re + 1 / N
            continue
        p = pows(i, K)
        
        re = re +  pow(0.5, p) / N
    print(re)
    


if __name__ == "__main__":
    main()

Solution (Python):
import math
n,k = map(int, input().split())
ans = 0
if n>=k:
    ans += 1-k/n
iterate = k if n>k else n
for i in range(1,iterate+1):
    temp = math.log2(k/i)
    temp = int(temp) if temp%1==0 else int(temp)+1
    ans += (1/n)*math.pow(0.5,temp)
print(format(ans, '.20f'))

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

def get_n(num, K):
    now_score = num
    for i in range(20):
        if now_score >= K:
            return i
        now_score *= 2

for i in range(1, N+1):
    n = get_n(i, K)
    i_score = (1/N) * ((1/2)**n)
    result += i_score

print(result)

Solution (Python):
import numpy as np
 
n, k = map(int, input().split())
ans = 0
 
for i in range(1, n + 1):
  if i>= k:
    ans += 1 / n
  else:
    ans += np.power(1 / 2, np.ceil(np.log2(k / i))) / n
    
print(ans)

Solution (Python):

import numpy as np
import types
import copy
import math


l = list(map(int, input().split()))
N = l[0]
K = l[1]
win_rate = 0

def calcNeedCount(d, k):
    point = d
    count = 0
    while point < k:
        point = point * 2
        count += 1

    return count


n = copy.deepcopy(N)
while n > 0:
    dice = n

    
    need = calcNeedCount(dice, K)
    

    win_rate += (1/N) * math.pow(1/2, need)

    n += -1


print(win_rate)

Solution (Python):
import math

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

for i in range(1, N + 1):
    if i < K:
        target = K / i
        exponent = math.log(target, 2)
        prob = (1 / N) * (1 / 2)**math.ceil(exponent)
        prob_sum += prob
    else:
        prob = 1 / N
        prob_sum += prob
print(prob_sum)

Solution (Python):
import math
a=[]
a=input().split(" ")
N=int(a[0])
K=int(a[1])

q=0
if K<=N:
    for i in range(1,K):
        p=(0.5)**(math.ceil(math.log2(K/i)))
        q=p+q
    x=q/N
    y=(N-K+1)/N
    print(x+y)
elif N<K:
    for i in range(1,N+1):
        p=(0.5)**(math.ceil(math.log2(K/i)))
        q=p+q
    print(q/N)

Solution (Python):
import collections
import decimal

N, K = map(int,input().split())
coin = [0] * (K+1)
ans = 0

for i in range(K-1,0,-1):
    coin[i] += 1
    for j in range(1,20):
        if i % (2**j) == 0:
            coin[i//(2**j)] += 1

if N >= K:
    ans += N-K+1

A = collections.Counter(coin[1:min(N+1,K)]).most_common()

for tmp in A:
    ans += (0.5)**tmp[0] * tmp[1]

print(decimal.Decimal(ans/N))

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

C=0
for i in range(1,N+1):
    c=i
    for j in range (10**5):
        if c >= K:
            break
        else:
            c *= 2
    C += (1/N)*(0.5)**j
print(C)

Solution (Python):
import math

def main():
    temp = input().split()
    N = int(temp[0]); K = int(temp[1])
    need_omote = []
    for n in range(1, N+1):
        temp = float(K/n)
        count = 0
        while(1):
            if(temp <= 1):
                break;
            else:
                temp = temp/2
                count += 1
        need_omote.append(count)
    kakeru = 0
    for n in range(N):
        if(need_omote[n] > -35):
            kakeru += 1/(2**need_omote[n])
    ans = float(kakeru/N)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):






import math





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





ans = 0
if K > 1:
    for i in range(1,N+1):
        ans += (1/2)**(max(math.floor(math.log((K-1)/i, 2)) + 1, 0))/N
else:
    ans = 1





print(ans)

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

Solution (Python):
n,k=map(int,input().split())
a=[]
en=0
for s in range(1,n+1):
 m=0
 en=0
 while en==0:
  if (2**m)*s<k:
    m+=1
  else:
    a.append(1/2**m)
    en+=1

print(sum(a)/n)

Solution (Python):
import math

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

p = 0.0
for i in range(1, N+1):
    if i < K:
        a = math.log2(float(K)/float(i))
        if a.is_integer():
            a = int(a)
        else:
            a = int(a) + 1
        p1 = (1/float(N))*pow(0.5, a)
        p = p + p1
    elif i >= K:
        p = p + (1/float(N))

print(p)

Solution (Python):
n, k = list(map(int, input().split()))
def times(i):
    a = 0
    for x in range(0, k):
        if i*(2**x)>=k:
            a = round((1/n)*(0.50**x),15)
            break
    return a
       
ans = 0
for i in range(1, n+1):
        ans += times(i)
print(ans)

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

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

    ans += (0.5 ** cnt) / n

print(ans)

Solution (Python):
import math

n, k = map(int, input().split())
a = 0
ans = 0.0
for i in range(1,n+1):
    if i*2 < k:
        a = math.log2(k/i)  
        c = math.ceil(a)
        b = float(1/n)
        d = (1.0/2.0) ** c
        ans += b*d

    elif i < k < i*2:
        ans += float(1/n)*0.5

    else:
        b = float(1/n)
        ans += b*1

print(ans)

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

p=1/n
if n>=k:
    l=k
    win=(n-k+1)/n
else:
    l=n+1
    win=0
lst=[]
for i in range(1,l):
    x=i
    count=0
    while x < k:
        x*=2
        count += 1
    lst.append(count)
result=0
for i in lst:
    result+=(1/2)**i
print(result*p+win)

Solution (Python):
import math

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

ret = (N - K + 1) if N > K else 0
counter = N + 1 if N < K else K
C = 1 / N
tmp = 0
e = math.ceil(math.log2(K/1))
pro = 1
for i in range(e):
    pro *= 2
tmp = 1/pro
for  i in range(2,counter):
    e_next = math.ceil(math.log2(K/i))
    if e_next < e:
        e = e_next
        pro /= 2
    tmp += 1/pro
print((ret + tmp)/N)

Solution (Python):
from math import log2, ceil

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

ans = 0.

for k in range(1, N+1):
    if k >= K:
        ans += 1. / float(N)
        continue
    tmp1 = float(ceil(log2(K / k)))
    tmp = 0.5**tmp1
    ans += tmp / float(N)

print(ans)

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

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

jou_list = [0 for _ in range(N)]
n_list = [i+1 for i in range(N)]

for i in range(N):
    m = 0
    ii = n_list[i]
    while ii < K:
        m += 1
        ii *= 2
    jou_list[i] = m

ans = 0
for i in range(N):
    ans += 1/(2**jou_list[i])

ans = ans/N

print(ans)

Solution (Python):
import math

n, k = map(int, input().split())
ans = 0
for i in range(1, n + 1):
    if k/i > 1:
        l = math.log2(k / i)
        a = math.ceil(l)
        ans += (1 / n) * ((1 / 2) ** a)
    else:
        ans += 1/n

print(ans)

Solution (Python):
import math

n, k = map(int, input().split())
result = 0
for first_dice in range(1, n + 1):
    front_count = max(math.ceil(math.log(k / first_dice, 2)), 0)
    result += (1 / n) * (1 / 2) ** front_count

print(float(result))

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

import math
val = K
curr_max = N
result = 0

pow_count = 0
while curr_max >= 1:
    if curr_max >= val:
        ceil = curr_max-math.ceil(val)+1
        result += ceil/N * ((0.5) ** pow_count)
        curr_max = math.ceil(val-1)
    val *= 0.5
    pow_count += 1

print result

Solution (Python):
import math
N, K = input().split(" ")
N, K = int(N), int(K)
P = 0
if (N < K):
  for n in range(1,N+1):
    P += 1/(N*pow(2,math.ceil(math.log2(K)-math.log2(n))))
else:
  for n in range(1, K+1):
    P += 1/(N*pow(2,math.ceil(math.log2(K)-math.log2(n))))
  P += (N-K)/N
print(P)

Solution (Python):
from decimal import Decimal, ROUND_DOWN
N,K = map(int, input().split())
l = []
for i in range(N):
    if i >= K:
        break
    a = 0
    for j in range(K):
        if j == 0:
            a = i+1
        else:
            a = a * 2
        if a >= K:
            break
    kakuritsu = 1/N*(0.5**j)
    l.append(kakuritsu)
s = sum(l)
if N > K:
    ans = s + (N-K)/N
else:
    ans = s
print("{0:.10f}".format(Decimal(ans)))

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

total = []
s_c = 0
for i in range(n):
    s = i+1
    num = 1
    if s <= (k/2) :
        while s*2 < k:
            num += 1
            s = s*2
    elif s >= k:
        break
    s_c += 1
    total.append(num)
o = 0
for j in range(s_c):
    o += (1/n) * (0.5 ** total[j])
if s_c != n:
    o += (n-s_c)/n
print(o)

Solution (Python):
import math

e = 10**(-7)
n,k = map(int, input().split())
ans = 0
for i in range(1,n+1):
    if i >= k:
        ans += 1
    else:
        ans += (1/2)**(int(math.log2((k-e)/i))+1)
    
print(ans / n)

Solution (Python):
import math
N,K=map(int,input().split())
tmp=0
for i in range(N):
  if K>(i+1):
    B=math.ceil(math.log2(K/(i+1)))
  else:
    B=0
  C=1/N/(2**B)
  tmp+=C
print(tmp)

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

answer = 0
for c in range(1, n + 1):
    coin_num = 0
    while c < k:
        c *= 2
        coin_num += 1
    prob = (1 / n) * (1 / 2) ** coin_num
    answer += prob

print(answer)

Solution (Python):

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

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

poss = 0
posssum = []
for i in range(1,N+1):
	point = i
	cou = 0
	while point <= K-1:
		point = 2*point
		cou=cou+1

	poss = 1.0/float(N) * 0.5 **(cou)
	posssum.append(poss)

print(sum(posssum))

Solution (Python):
import sys
import math

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

res = 0.0

for i in range(1,n+1):
  if k <= i :
    res = res + 1
    continue
  for j in range(1,math.floor(math.log2(k))+2):
    if (i * (2 ** j)) >= k :
      res += 0.5 ** j
      break
res = res / n
print(res)

Solution (Python):
def gcd(a, b):
    while b:
	    a, b = b, a % b
    return a

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

n, k = list(map(int, input().split()))
a_list =[]
for i in range(n):
    cnt = 0
    tmp = i+1
    while tmp < k:
        tmp *= 2
        cnt += 1
    if i < k:
        a = n*2**cnt
    else:
        a = n
    a_list.append(a)
_lcm = a_list[0]
for i in range(1, n):
    _lcm = lcm(_lcm, a_list[i])
tmp = 0
for a in a_list:
    tmp += _lcm / a
print(tmp/_lcm)

Solution (Python):
import math

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

ans = 0

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

Solution (Python):
n,k = map(int,input().split())
dice = [int(i+1) for i in range(n)]
point = 0
prob = 0
ans = 0
for i in range(n):
    point += dice[i]
    prob += 1/n

    while point <= k-1:
        point *= 2
        prob *= 0.5

    ans += prob
    point = 0
    prob = 0

print(ans)

Solution (Python):
N, K = (int(x) for x in input().split())

ans = 0

for n in range(1,N+1,1):
    score = n
    temp = 1
    while True:
        if K <= score:
            ans += temp/N
            break
        score *= 2
        temp /= 2

print(ans)

Solution (Python):
import sys
import os

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


count=[0]*N

KK=K
i=0
while  KK >= 1:
    i=i+1
    for j in range(int(KK)):
        if j<N and (j+1)!=KK:
            count[j]=count[j]+1
        
    KK=KK/2

sum=0
for l in range(N):
    sum=sum + (1/N)*(1/2)**(count[l])


print(sum)

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

import math


p = 0

for i in range(n+1):
    if i>0:
        if i>=k:
            p += 1
        else:
            p += 2**(int(30+math.log2(i/k))-30)
print(p/n)

Solution (Python):
import math
Input = input().split()
N = float(Input[0])
K = float(Input[1])

result = float(0)
p = float(1/N)
i = 0

if N >= K:
    result = result + (N - K + 1) * p
    N = K - 1

while K > 1:
    K = K / 2
    x = float(math.ceil(K))
    i += 1
    if N >= x:
        q = 0.5**i
        result = result + (N - x + 1) * q * p
        N = x - 1

print(result)

Solution (Python):
n,k=map(float,input().split())
ans=0
l=[[k,0]]
k1=k
ll=0
while k1>1:
    k1/=2
    ll+=1
    l+=[[k1,ll]]
l.reverse()
ll+=1
l+=[[100001,ll]]
for i in range(ll):
    if l[i+1][0]<n:
        ans+=(int(l[i+1][0]-0.000001)-int(l[i][0]-0.000001))/n/2**l[i][1]
    else:
        ans+=(n-int(l[i][0]-0.000001))/n/2**l[i][1]
        break
print(ans)

Solution (Python):

import numpy as np
import math

N,K=map(int,input().split())
prob = [0]*N


for ii in range(1,N+1):
    index = math.ceil(np.log2(K/ii))
    if index <= 0:
        prob[ii-1] = 1/N
    else:
        prob[ii-1] = 1/N * (1/2)**index

print(sum(prob))

Solution (Python):

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

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


ans = 0

def calc(i):
    bb = 1
    while i * (2 ** bb) < K:
        bb +=1    
    return bb

for i in range(1, N + 1):
    if i >= K:
        ans += 1 / N
    else:
        y = calc(i)
        ans += 1 / N * (1/2) ** y

print(ans)

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

Solution (Python):


import sys
import math
input = sys.stdin.readline



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


max_pow = math.ceil(math.log2(K) + 0.9)

one_half = [0] * (max_pow + 1)
one_half[0] = 1
for i in range(1, max_pow + 1) :
    one_half[i] = one_half[i - 1] * 0.5

ans = 0
for i in range(1, N + 1) :
    pow_num = math.ceil(math.log2(K / i))
    
    if pow_num <= 0 :
        ans += 1
    else :
        ans += one_half[pow_num]

print(ans / N)

Solution (Python):

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

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

print(ans)

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

rate = 0

temp = 1
cnt = 0

while True:
  if temp >= k:
    break
  else:
    temp *= 2
    cnt += 1

for i in range(1, n + 1):
  if i * (2 **cnt) >= k > i * (2 ** (cnt - 1)):
    rate += 1 / n * 0.5 ** cnt
  else:
    cnt = max(0, cnt - 1)
    rate += 1 / n * 0.5 ** (cnt)

print(rate)

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

if __name__=="__main__":
    sol()

Solution (Python):
def main():
    N, K = map(int, input().split())
    sum = 0.0

    if N - K >= 0:
        sum = sum + N - K + 1.0

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

    print(round(sum/N, 10))

if __name__ == "__main__":
    main()

Solution (Python):

N, K = map(float, input().split())
ans = 0.0

import math 

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

Solution (Python):
import sys
import numpy as np

N, K = input().split()

N = float(N)
K = float(K)

c = 0.0

if N > K:
    A = K/N
else:
    A = 1.0

for i in range(1,int(N)+1):
    if i > K:
        c += 1/N
    else:
        n = np.ceil(np.log2(K/i))
        c += 1/N*(1.0/2.0)**n

print(c)

Solution (Python):
import math
from fractions import Fraction

NK = [int(i) for i in input().split()]
answer = [0.0] * NK[0]

for i in range(NK[0]):
    f = float(math.log2(NK[1]) - math.log2(i+1))
    if(f.is_integer()):
        value = int(math.log2(NK[1]) - math.log2(i+1))
    elif(i+1 >= NK[1]):
        value = 0
    else:
        value = int(math.log2(NK[1]) - math.log2(i+1)) + 1
    if(value < 0):
        value = 0
    answer[i] = Fraction(1, (NK[0] * (2**value)))
print(float(sum(answer)))

Solution (Python):
import math

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

prob = 0

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

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

def get_n(num, K):
    now_score = num
    for i in range(20):
       if now_score >= K:
           return i
       now_score *= 2

for i in range(1, N+1):
    n = get_n(i, K)
    i_score = (1/N) * ((1/2)**n)
    result += i_score

print(result)

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

import math
Ans = 0

if K < N:
    for X in range(1, K+1):
        R = math.log(K/X, 2)
        S = math.ceil(R)
        Ans = Ans + (0.5**S / N)
    Ans = Ans + (N-K)/N
    print(Ans)

if K == N:
    for X in range(1, K+1):
        R = math.log(K/X, 2)
        S = math.ceil(R)
        Ans = Ans + (0.5**S / N)
    print(Ans)
    
if K > N:
    for X in range(1,N+1):
        R = math.log(K/X, 2)
        S = math.ceil(R)
        Ans = Ans + (0.5**S / N)
    print(Ans)

Solution (Python):
import math 

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

result = 0

for i in range(1,n+1):
	if i < k :

		log_i = math.log2(k/i)
		ceil_i = math.ceil(log_i)

		result += math.pow(0.5, ceil_i)/n

	else:
		result += 1/n

print(result)

Solution (Python):
import math

n, k = map(int, input().split())
limit = 1 / n
ans = 0
for x in range(1 , n + 1):
    num = math.pow(2, -1 * math.ceil(math.log(k / x, 2)))
    num = num / n
    if num > limit:
        num = limit
    ans = ans + num
    if ans >= 1:
        break
print("{:.12f}".format(ans))

Solution (Python):
def main():
    n, k = map(int, input().split())
    res = 0
    t=0
    for i in range(1, n + 1):
        count = 0
        j = i
        while (j < k):
            j *= 2
            count += 1
        if i == 1:
            t = count
            res += 1
        else:
            res += 2 ** (t - count)
    res = res/((2**t) *n)
    print(res)

if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
import math
n,k=list(map(int,input().split()))
sum1=0
for i in range(1,n+1):
    if i>=k:
        sum1+=1/n
        
    else:
        
        res=math.log(k/i,2)
        res=math.ceil(res)
        sum1+=(1/n)*(0.5**res)
print(sum1)

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

a = math.fsum([(1/n) * ((1/2)**math.ceil(math.log(k/i, 2))) for i in range(1, min(k, n+1))])

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

Solution (Python):
import math

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

ans/=n

print(ans)

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

f = 0
ans = 0

if N >= K:
    ans = (N - K + 1) / 1.0
    f = 1
K = K - 1

a = []
i = 0
while(2 * N < K):
    a.append(0)
    i += 1
    K = K // 2

if f == 0:
    i += 1
    a.append(N - K //2)
    K = K // 2

while(K != 0):
    a.append(K - K // 2)
    i += 1
    K = K // 2

bunsi = 0

for j in range(len(a)):
    bunsi += a[j] * pow(2, i - j - 1)
ans += bunsi / pow(2, i)

print(ans / N)

Solution (Python):
import math
a, b = (int(_) for _ in input().split())  
res = float(sum([(1/2 ** (math.ceil(math.log2(b/i)))) if i < b else 1 for i in range(1,a+1)]) / a)
print(res)

Solution (Python):
N,K = map(int,input().split())
ans = 0
for p in range(1,min(N+1,K+1)):
    for q in range(1,K+10):
        if 2**(q-1) * p <= K - 1 and 2**q * p >= K:
            ans += (1/N)*(1/2)**q
            break
if N < K:
    ans = ans
else:
    ans += (N-(K-1))/N
print(ans)

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

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

ans = 0

if N >= K:
    ans += (N - K + 1) / N
n = K - 1


tmp = 2
while n >= 1:
    a = 0
    if n == 1:
        a = 1 / tmp / N
    else:
        if n > N:
            if n % 2 == 1 and n // 2 < N:
                a = (N - n // 2) / tmp / N
            if n % 2 == 0 and n // 2 < N:
                a = (N - n // 2) / tmp / N
        else:
            a = (n - (n // 2)) / tmp / N
    tmp *= 2
    n //= 2
    ans += a
    

print(ans)

Solution (Python):
import math

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

total = 0
for d in range(1, N + 1):
    if d < K:
        ceil = math.ceil(math.log2(K) - math.log2(d))
        total += 1 / (2 ** ceil)
    else:
        total += 1

print(total / N)

Solution (Python):
n,k=map(int,input().split())
kaisu=[]
for i in range(1,n+1):
    if i >=k:
        kaisu.append(1)
    else:
        for j in range(1,100):
            if pow(2,j)>=(k/i):
                kaisu.append(1/2**j)
                break
ans=sum(kaisu)/n
print(ans)

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

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

prob = 0.0
t = 0

for i in range(1, n+1):
    point = i
    for j in range(0, k+1):
        point = i * 2 ** j
        if point >= k:
            t = j
            break
    prob += (1.0/n) * (0.5)**t

print(prob)

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

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

print(res)

Solution (Python):
n,k=map(int,input().split())
prob=0.0
if n>=k:
  prob+=(n-k+1)/n
mn=min(n+1,k)
for i in range(1,mn):
  check=i
  count=0
  while True:
    check*=2
    count+=1
    if check>=k:
      break
  prob+=pow(0.5,count)/n
print(prob)

Solution (Python):
from math import log

n,k = (int(num) for num in input().split())
p = 1/n
ans = 0.0

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

Solution (Python):
import math

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

ans = 0
for i in range(N):
    n = math.log2(k) - math.log2(i+1)
    if n < 0:
        n = 0
    if n > 0:
        n = math.ceil(n)
    ans = ans + 1/((2**n)*N)
print(ans)

Solution (Python):
import math

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

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

for i in range(1, N+1):
    P.append(1/N * (1/2)**func(i, K))



print(sum(P))

Solution (Python):
a = map(int,input().split())
a = list(a)
for l in range(2):
    a[l] = int(a[l])
c = 0
b =[]
for i in range(1,a[0]+1):
    j = 0
    while True:
        infer = a[1]/i
        refer = (2)**j
        if refer >= infer:
            c = (1/refer)/a[0]
            b.append(c)
            break
        else:
            j += 1
print(sum(b))

Solution (Python):
import math
import sys
from decimal import *
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()

n, k = MI()
getcontext().prec = 80
ans = Decimal(0)
ans2 = Decimal(0)
for i in range(1, n+1):
    if i == k:
        break
    ans += (Decimal((1/n)) * Decimal((Decimal(0.5) ** math.ceil(math.log(k/i, 2)))))
if n - k + 1 > 0:
    
    ans2 += (Decimal((1/n)) * Decimal((n-k+1)))
print(ans+ans2)

Solution (Python):
import math

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

a = 0
b = []

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

print(sum(map(lambda x: 1/n * x, b)))

Solution (Python):
S = list(map(int, input().split()))
S1 = S[0]
sum = 0
c = 0
coin = 0
for i in range(1,S[0]+1):
    k = i
    while k < S[1]:
        c = c + 1
        k = k * 2
    sum = sum + 1/S[0] * (0.5 ** c)
    
    c = 0
print(sum)

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

ans = 0

while i <= N:
    j = 0
    n = 0
    while n <= K-1:
        n = i * 2**j
        j += 1
    
    ans += 1/N * (1/2)**(j-1)
    i += 1
            
print(ans)

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

    sum_prob = 0

    for dice in range(1, n+1):
        if dice >= k:
            sum_prob += (1 / n)
            continue
        coin = 1
        while dice * (2 ** coin) < k:
            coin += 1

        sum_prob += (1 / n) * (0.5 ** coin)

    print(sum_prob)

if __name__ == "__main__":
    main()

Solution (Python):
dice, target = input().split()
dice, target = int(dice), int(target)

dev = 1.0
OK = 0
rem = dice
while 1:
  if rem <= 0:
    break
  elif rem >= target:
    OK += (rem-target+1)*dev
    rem = target-1
  target = int((target+1)/2)
  dev /= 2.0
      
print('{:.10f}'.format(OK/dice))

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

def need(x, y): 
  for i in range(30):
    if x*(2**i) >= y:
      return i

for i in range(n):
  ned = need(i+1, k)
  for j in range(ned):
    a += (1/2)**(j+1)
  ans = 1 / n * a
  
print(1-ans)

Solution (Python):
N, K = map(int, input().split())
import numpy as np
 
ans = 0
if  N >= K:
    ans+= (N-K+1)/N
    max_N = K-1
else:
    max_N = N
a_=0
for x in range(max_N):
    a_+=pow(1/2,np.ceil(np.log2(K/(x+1))))

ans += a_/N
print(ans)

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

def point(check):
    count = 0

    while check < K:
        count += 1
        check = check * 2

    return 2**count


for i in range(N):
    temp = point(i+1)
    deno += 1/(N*temp)

print(deno)

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

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

print(result)

Solution (Python):
def solve():
    n, k = map(int, input().split())
    ps = 0.0
    for i in range(1, n+1):
        sum = i
        p = 1.0 / n
        while(sum < k):
            p /= 2.0
            sum *= 2
        ps += p
    print(ps)

if __name__ == '__main__':
    solve()

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

Solution (Python):
N,K = map(int,input().split())
num = 0
point = 0
cnt = 0
for i in range(1,N+1):
    if 1 <= i and i <= (K-1):
        point = i
        cnt = 0
        while 1:
            if point >= K:
                break
            else:
                point *= 2
                cnt += 1
        num += float((1/N) * ((1/2) ** cnt))
    elif i >= K:
        num += float((1/N))

print(num)

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

Solution (Python):


n, k = map(int, input().split())
import math
import numpy as np
pro = 0
for i in range(1,n+1,1):
    if i < k:
        
        
        pro += 0.5**math.ceil(np.log2(k/i))
    else:
        pro += 1
print(pro/n)

Solution (Python):
import math

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

win = 0.
prob = 1 / n
for i in range(1, n + 1):
    if i >= k:
        win += prob
        continue
    board = math.log2(k) - math.log2(i)
    head = math.ceil(board)
    win += prob * (0.5 ** head)

print(win)

Solution (Python):
import math

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

tmp=0

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

Solution (Python):
import math


N, K = map(int,input().split())
ans = 0
for i in range(1,N+1):
    n = math.ceil(math.log2(K/i))
    if i <= K:
        ans += pow(0.5,n) / N
    else:
        ans += 1 / N

print(ans)

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

for num in range(N):
    num = num + 1
    counter = 0
    while num < K:
        num *=2
        counter += 1
    p += 1/N * (1/2) ** counter
    
print(p)

Solution (Python):
N, K = input().split()
N = int(N)
K = int(K)
ans = float(0)
gro_bairitu = 1


def probability(num, K, pro, loc_bairitu):
    global ans, gro_bairitu
    if num >= K:
        ans += pro
    else:
        loc_bairitu *= 2
        if loc_bairitu > gro_bairitu:
            gro_bairitu = loc_bairitu
        probability(2 * num, K, float(pro) / 2, loc_bairitu)


for i in range(N, 0, -1):
    probability(i, K, float(1) / N, gro_bairitu)

print("{:.10f}".format(ans))

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


ans = 0

for i in range(1,N+1):
    if i >= K:
        ans += 1/N
    else:
        max_coin = math.ceil(math.log(K/i,2))
        ans += (0.5)**max_coin/N
print(ans)