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())
ans = 0 
for i in range(1, n+1):
  cnt = 0
  while i < k:
    i *= 2
    cnt += 1
  ans += 0.5 ** cnt
print(ans*(1/n))

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

stack=[i for i in range(1,n+1)]

ans=0
while stack:
    x =stack.pop(-1)
    tmp=0
    while x<k:
        x*=2
        tmp+=1
    ans+=0.5**tmp
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):
    n=ceil(log(K/i, 2))
    if n>=0:
        ans+=(1/(N*2**n))
    else:
        ans+=1/N
    
print(ans)

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

ans = 0
for i in range(1, N + 1):
    if i >= K:
        ans += 1
    else:
        cnt = 0
        while i < K:
            i *= 2
            cnt += 1
        ans += pow(2, -cnt)
print(ans / N)

Solution (Python):
from bisect import bisect_right as bir
N, K = map(int, input().split())

t = [K]
i = K
while i > 1:
    i += 1
    i //= 2
    t.append(i)
t.sort()
l = len(t)


def log(i):
    return l - bir(t, i)


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

print(ans)

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    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*(2**cnt))
    print(ans)

    
resolve()

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

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

def main():
    n,k = readInts()
    ans = 0
    
    for i in range(1,n+1):
        prob = 1
        nk = i 
        while nk < k:
            nk *= 2
            prob /=2
        ans += prob
    
    ans /= n
    print(ans)
if __name__ == '__main__':
  main()

Solution (Python):
import sys

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

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

print(res / N)

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

import math

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

ans /= N

print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

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

Solution (Python):
def f(n):
    x = 1
    while n*2**x<K:
        x += 1
    return x
N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
    if i<K:
        ans += 2**(-f(i))/N
    else:
        ans += 1/N
print(ans)

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

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

from math import ceil,log
n,k = myinput()
ans = 0
for i in range(n):
    m = i+1
    if m<k:
        x = ceil( log(k/m,2) )
        ans += 1/n * ( (1/2)**x )
    else:
        ans += 1/n
print(ans)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    P = 0
    for i in range(1, N + 1):
        coins = 0
        k = i
        while k < K:
            coins += 1
            k *= 2
        P += pow(0.5, coins) / N
    print(P)

    return 0

if __name__ == "__main__":
    solve()

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

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

ans = 0

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

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:
        x = math.ceil(math.log2(k/i))
        ans += 1/n/(2**x)

print(ans)

Solution (Python):
def main():
    n, k = map(int, input().split())
    answer = 0.0
    for i in range(1, n + 1):
        now = i
        count = 0
        while now < k:
            now *= 2
            count += 1
        answer += pow(0.5, count)
    answer /= n
    print(answer)


if __name__ == '__main__':
    main()

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

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

print(sum(cnt)/n)

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

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

print (ans / N)

Solution (Python):
import sys
input = sys.stdin.readline
from collections import *

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

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

print(ans)

Solution (Python):
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
  anss=1/n
  co=0
  j=i
  while j<k:
    co+=1
    j*=2
  anss*=1/(1<<co)
  ans+=anss
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 = math.ceil(math.log2(k / i))
        ans += 1 / (2 ** m) / n
    else: 
        ans += 1 / n
print(ans)

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

ans = 0

for i in range(1,n+1):
    num = 0
    p = i
    while True:
        if p >= k:
            x = (1/n) * (1/2)**num
            ans += x
            break
        p *= 2
        num += 1


print(ans)

Solution (Python):
import math


def main():
    N, K = list(map(int, input().split(' ')))
    ans = 0
    for k in range(1, N + 1):
        if k < K:
            n = math.ceil(math.log2(K / k))
            ans += 1 / (N * (2**n))
        else:
            
            ans += 1 / N
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from math import log2

n, k = map(int, input().split())
ans = 0
for i in range(n):
    x = log2((k / (i + 1)))
    if x < 0:
        x = 0
    else:
        if x != int(x):
            x = int(x) + 1
    ans += (1 / n) * (0.5**x)
print('{:.12f}'.format(ans))

Solution (Python):
def dice_and_coin(n, k):

    ans = 0

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

    return ans

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

if __name__ == '__main__':
    main()

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

accuracy = 0
for i in range(1, N+1):
    for j in range(19):
        if i*(2**j) > K-1:
            accuracy += (1/N) * (1/2) ** j
            break
print(accuracy)

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

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

Solution (Python):

import sys
import math


def solve(N: int, K: int):
    s = max(0, N - K + 1) / N
    for k in range(1, min(N+1, K)):
        current_order = math.ceil(math.log(K / k, 2))
        s += (1 / 2) ** current_order / N
    print(s)
    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):
import numpy as np

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

p1 = max(N - K + 1, 0) / N
p2 = 0.
l2K = np.log2(K)
for k in range(1, min(K, N+1)):
    p2 += (0.5) ** np.ceil(l2K - np.log2(k))

print(p1 + p2 / N)

Solution (Python):

import math

def main():
    N, K = map(int, input().split(' '))
    
    result = 1 / N * sum([math.pow(0.5, math.ceil(math.log2(K / n))) if n < K else 1.0 for n in range(1, N + 1)])
    print('{:.12f}'.format(result))


if __name__ == '__main__':
    main()

Solution (Python):


n, k = map(int, input().split())
P = 0
for i in range(1, n + 1):
    if i >= k:
        P += (n - i + 1) / n
        break
    pow = 1
    while i * 2**pow < k:
        pow += 1
    P += 0.5**pow / n
print(P)

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

@lru_cache(maxsize=None)
def f(x):
    return f(x * 2) * 0.5 if x < K else 1

ans = fsum(f(i + 1) for i in range(N)) / N
print(ans)

Solution (Python):
N,K=list(map(int,input().split()))
per=[1/N]*N
count=0
for i in range(0,min(K-1,N)):
    per[i]=i+1
for i in range(0,min(K-1,N)):
    while True:
        count+=1
        per[i]*=2
        if per[i]>=K:
            per[i]=(1/N)*((1/2)**count)
            count=0
            break
print(sum(per))

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

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


print(probability)

Solution (Python):
n,k=map(int,input().split())
ans=0
li=[k]
tmp=k
from math import ceil
for i in range(k):
    tmp/=2
    li.append(ceil(tmp))
    if tmp<1:
        break



now=n
for i,v in enumerate(li):
    if now>=v:
        ans+=(now-v+1)/(2**i)
        now=v-1
print(ans/n)

Solution (Python):
import math

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

output = 0
for i in range(1, N+1):
    cnt = 0
    while True:
        if i * 2 ** cnt >= K:
            break
        cnt += 1
    output += (1/N) * (0.5 ** cnt)

print(output)

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

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

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

Solution (Python):
N,K =map(int,input().split())
Pi = 1/N
for i in range(100):
    if N*(2**i) >= K:
        fre = i
        break
    else:
        continue
Sum = 0
for j in range(N):
    Nu = N - j
    if (Nu*(2**fre)) >= K:
        Sum += Pi*((1/2)**fre)
    else:
        for k in range(100):
            fre += 1
            if (Nu*(2**fre)) >= K:
                Sum += Pi*((1/2)**fre)
                break
print(Sum)

Solution (Python):
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) * (1/2**count)
print(ans)

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

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

ans = 0
for i in range(1, N+1, 1):
    j = i
    c = 0
    if i<=K-1:
        while j<=K-1:
            j = j * 2
            c = c + 1
        ans = ans + (1/N)*((1/2)**c)
    else:
        ans = ans + (1/N)*((1/2)**c)
print(ans)

Solution (Python):
import math
N, K = map(int, input().split())
p = 0
if N >= K:
    p += (N - K + 1) / N
    
for i in range(1, min(N + 1, K)):
    n = math.ceil(math.log2(K / i))
    p_i = (1 / N) * (0.5 ** n)
    p += p_i

print(p)

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

print("{:.15f}".format(p))

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

probSum=0
for diceNum in range(1,N+1):
    if (diceNum<K):
        numHeadNeeded = math.ceil(math.log(K/diceNum,2))
    else:
        numHeadNeeded=0
    
    prob = (1/N)*((1/2)**(numHeadNeeded))
    probSum = probSum+prob

print(probSum)

Solution (Python):
n,k = map (int,input().split())
ans = n + 0.0
s = 1
t = k-1
while t >= 1:
    a = min (t,n)
    ans -= a / 2**s
    t = (k-1) // 2**s
    s += 1
print(ans/n)

Solution (Python):
N, K = map(int, input().split())
res = []
for n in range(1, N + 1):
    
    t = 0
    s = n
    while s < K:
        s *= 2
        t += 1
    res.append((1 / N) * (1 / 2 ** t))
print(sum(res))

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

    prob = 0
    for point in range(1, N+1):
        if point <= K - 1:
            p = (1/N) * (1/2.0)**math.ceil(math.log2(K/point)) 
            prob += p
        else:
            p = 1/N
            prob += p

    print(prob)
if __name__ == "__main__":
    main()

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

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

print(ret)

Solution (Python):

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

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

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

Solution (Python):
import math

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

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

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

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

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

print(ans)

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

for i in range(1, n + 1)[::-1]:
    if i >= k:
        ref += 1
    else:
        while i < k:
            i *= 2
            cnt += 1
            if i >= k:
                ref += 1/(2**cnt)
                cnt = 0
                break
print(ref/n)

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

Solution (Python):
import math
n,k=map(int,input().split())
n_lis=[int(i) for i in range(1,n+1)]
p=float(1/n)
p_lis=[]
for i in range(n):
    if n_lis[i]<k:
        atai=float(k/n_lis[i])
        kaisu=-(-math.log(atai,2)//1) 
        p_lis.append((1/2)**(kaisu))
    else:
        p_lis.append(1)

print(p*sum(p_lis))

Solution (Python):

import numpy as np
n,k=map(int,input().split())
n_lis=[int(i) for i in range(1,n+1)]

p=float(1/n)
p_lis=[]

for i in range(n):
    count=0
    if n_lis[i]<k:
        atai=float(k/n_lis[i])

        for j in range(10000):
            atai=float(atai/2)
            count+=1

            if atai<=1:
                break
        
        p_lis.append((1/2)**(count))
    
    else:
        p_lis.append(1)

print(p*sum(p_lis))

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 

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

Solution (Python):

import collections
import itertools as it
import math

 


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





ans = 0

for i in range(1, n+1):
    for ntoss in range(10000000):
        
        if i * (2 **  ntoss) >= k:
            ans += (1 / n) * ((1 / 2) ** ntoss)
            break
    
print(ans)

Solution (Python):


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

ans = 0.0
for i in range(1, N+1):
    point = i
    P = 1/N
    while True:
        if point >= K: break
        point *= 2
        P *= 1/2
    ans += P

print(ans)

Solution (Python):

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

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

Solution (Python):





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








ans = 0
p = 0

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

print(ans)

Solution (Python):
from math import * 

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

for i in range(1, N+1):
    if i >= K: c = 0
    else: c = ceil(log2(K/i))
    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):
    tmp = 1
    now = i
    while now < k:
        now = now*2
        tmp = tmp*0.5
    ans += tmp*(1/n)
print (ans)

Solution (Python):
import math

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

print(ans)

Solution (Python):
import math

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

for i in range(1,N+1):
    if i > K:
        x = 0
    else:
        x = math.log2(K)-math.log2(i)
        x = int(x) if x.is_integer() else int(x) + 1
    ans += (1/N) * pow(1/2,x)
print(ans)

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, k = MI()

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

    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):
def resolve():
    '''
    code here
    '''
    import math
    N, K = [int(item) for item in input().split()]

    res = 0

    for i in range(1,N+1):
        for n in range(int(math.log2(K))+3):
            if i * 2 ** n >= K:
                res += 1/N * 2 ** (-1 * n)
                break

        
    print(res)

if __name__ == "__main__":
    resolve()

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

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

Solution (Python):
n, k=map(int, input().split())
ans=0
for i in range(1, n+1):
    cnt=0
    p=i

    while p<k:
        p*=2
        cnt+=1
    
    ans+=(1/2)**cnt

print(ans*(1/n))

Solution (Python):
n, k=map(int, input().split())
ans=0
for i in range(1, n+1):
    cnt=0
    p=i

    while p<k:
        p*=2
        cnt+=1
    
    ans+=(1/2)**cnt

print(ans*(1/n))

Solution (Python):
def q3():
    import math
    N, K = (int(i) for i in input().split())

    ans = 0
    for n in range(1, N+1):
        if n >= K:
            ans += 1/N  
            continue
            
        c = math.ceil(math.log2(K/n))  
        
        ans += 1/N * (1/2)**c

    print('{:.9f}'.format(ans))


if __name__ == '__main__':
    q3()

Solution (Python):
n,k=map(int,input().split())
p=0
for i in range(1,n+1):
    r=k/i
    if r==1:
        p+=1
        continue
    m=1
    count=0
    while True: 
        if r>m:
            m=m*2
            count+=1
        else:
          break
    p+=1/m
p=p/n
print(p)

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

import math

p_k = 0


if N >= K:
    p_N = (N - (K-1))/ N

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

else:
    p_N = 0

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


p = p_k + p_N
print(p)

Solution (Python):
from math import ceil, log2

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

ans = 0
p = 1 / n
for i in range(1, n + 1):
    if i < k:
        m = ceil(log2(k / i))
        ans += p * (0.5 ** m)
    else:
        ans += p
print(ans)

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

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

    res +=  1/cnt

print(res/n)

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

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

    res += 1/n * 1/cnt

print(res)

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

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

print(res)

Solution (Python):


import math
from sys import stdin

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

Solution (Python):


import sys
import math


















def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, k = mi()
    p = 0
    for point in range(1, n+1):
        if point <= k-1:
            p += 1 / (n * pow(2, math.ceil(math.log(k / point, 2))))
        else:
            p += 1 / n
    print(p)

if __name__ == "__main__":
    main()

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

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

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

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

    np = 0
    for x in range(1, N + 1):
        p = 1
        while x < K:
            p *= 1 / 2
            x *= 2
        np += p

    ans = np / N

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def myAnswer(N:int,K:int) -> int:
   ans = 0
   for n in range(1,N+1):
      total = n
      counter = 0
      while total < K:
         total *= 2
         counter += 1
      ans += 1/N * (1/2)**counter
   return ans

def modelAnswer():
   return
def main():
   N,K = map(int,input().split())
   print(myAnswer(N,K))
if __name__ == '__main__':
   main()

Solution (Python):
def myAnswer(N:int,K:int) -> int:
   ans = 0
   for n in range(1,N+1):
      total = n
      if(total >= K):
         ans += 1/N
      else:
         counter = 0
         while True:
            total *= 2
            counter += 1
            if(total >= K):
               break
         ans += 1/N * (1/2)**counter
   return ans

def modelAnswer():
   return
def main():
   N,K = map(int,input().split())
   print(myAnswer(N,K))
if __name__ == '__main__':
   main()

Solution (Python):
def myAnswer(N:int,K:int) -> int:
   ans = 0
   for n in range(1,N+1):
      sub = K - n
      counter = 0
      total = n
      if(total >= K):
         ans += 1/N
         continue
      while True:
         total *= 2
         counter += 1
         if(total >= K):
            break
      ans += 1/N * (1/2)**counter
   return ans

def modelAnswer():
   return
def main():
   N,K = map(int,input().split())
   print(myAnswer(N,K))
if __name__ == '__main__':
   main()

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

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

print(s/n)

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

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

i = 1
ret = 0
while i <= n:
    cnt = 0
    tmp = k
    while i < tmp:
        tmp = tmp / 2
        cnt += 1
    ret += pow(0.5, cnt)
    i += 1
ret = ret / n
print(ret)

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

Solution (Python):
n,K = map(int,input().split())
p = min(n,K-1)
ans = 0
chk = [1]*(K-1)
k = K
for i in range(16):
  k /= 2
  if k == int(k):
    q = int(k*2-k-1)
  else:
    q = int(k*2-k)
  for i in range(q):
    chk[i] += 1
  if k <= 1:
    break
    

for i in range(p):
  ans += float(1/(2**chk[i]*n))
  
ans += max(0,(n-K+1)/n)
print(ans)

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

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

Solution (Python):

















import sys
sys.setrecursionlimit(10000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    
    
    
    
    
    
    
    
    
    
    ans = 0
    for i in range(1,n+1):
        
        a = 1
        m = i
        while m < k:
            m *= 2
            a *= (1/2)
        ans += a
    ans /= n
    print("%.12f"%(ans))
if __name__ == '__main__':
  main()

Solution (Python):
from collections import deque
import math
n,k=map(int,input().split())
l=deque()
i=0
while math.ceil(k/(2**i))!=math.ceil(k/(2**(i+1))):
  l.appendleft(math.ceil(k/(2**i)))
  i+=1
l=list(l)
count=len(l)
ans=0
for i in range(1,n+1):
  if i in l:
    count-=1
  ans+=1/(2**count)
print(ans/n)

Solution (Python):
from math import ceil
import numpy as np
N,K=map(int, input().split())


ans=max( (N-K+1),0) /N




lim=min(K-1,N)
for i in range(1,lim+1):
    x=ceil(np.log(K/i)/np.log(2))
    ans+=(1/N)*((0.5)**x)
print(ans)

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

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

    tmp /= 2**count

    ans += tmp
print(ans)