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



Sample input:
3 10


Sample output:
0.145833333333

Submission status: Accepted

Solution code:
#n = int(input())
import math
n, k = map(int, input().split())
#al = list(map(int, input().split()))
#al=[list(input()) for i in range(h)]

ans = 0

for i in range(1, n+1):
    if i>=k:
        heads_num=0
    else:
        heads_num = math.ceil(math.log2(k/i))
    add = (1/n)*((0.5)**heads_num)
    ans += add
    #ans += (1/n)*((0.5)**heads_num)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import ceil, log2

n, k = map(int, input().split())
ans = sum(1 / 2 ** ceil(log2(k / i)) for i in range(1, min(n, k) + 1))
print((ans + max(0, n - k)) / n)

Submission status: Accepted

Solution code:
from math import ceil
from math import log2

n, k = map(int, input().split())
ans = sum(1 / 2 ** ceil(log2(k / i)) for i in range(1, min(n, k) + 1))
print((ans + max(0, n - k)) / n)

Submission status: Accepted

Solution code:
import math
import time

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

ans = 0
for i in range(1,n+1):
    if k<=i:
        ans +=1
    else:
        for j in range(1,1000):
            if i*(2**j)>=k :
                ans += 1/(2**j)
                break
print( ans/n )

Submission status: Accepted

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

win = []

for i in range(1, n+1):
  if i >= k:
    win.append(1/n)
  else:
    t = True
    count = 0
    while t == True:
      if i < k:
        i = 2*i
        count += 1
      else:
        t = False
    win.append((((1/2)**count)*(min(n,k)/n))/min(n,k))

total = int(sum(win)*(10**12))/(10**12)
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N, K = list(map(lambda k: int(k), input().split(" ")))

# dice -> n
# n * 2^x >= K
# 2^x >= K / n
# x >= log2 (K / n)

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

Submission status: Accepted

Solution code:
import numpy
N, K = map(int, input().split())

p = 0
for i in range(1, N + 1):
    m = numpy.log2(K / i)
    
    if m < 0:
        m = 0
        
    p += 0.5 ** numpy.ceil(m)
    
print(p / N)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def kaisu(n,k):
  if n>=K:
    return k
  else:
    return kaisu(2*n,k+1)
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
  ans+=pow(2,20-kaisu(i,0))
ans=ans/(pow(2,20))
print(ans/N)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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

    ans /= N
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

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

ans1 = 0
ans2 = 0
for i in range(1, n+1):
    num = 0
    score = i
    if (i >= k):
        ans1 += 1
    else:
        while True:
            score *= 2
            num += 1
            if (score >= k):
                break
        ans2 += (0.5)**num
print((ans1+ans2)/n)

Submission status: Accepted

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

ans = 0.0

for i in range(1, N + 1):
    num = i
    t = 0
    while num < K:
        t += 1
        num *= 2

    ans += 1 / 2 ** t
    
print(ans / N)

Submission status: Accepted

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

p = 0

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

print(p)

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, k = inintm()

ans = 0

for i in range(1,n+1):
    b = 0
    for _ in range(1,18):
        if i >= k:
            break
        i *= 2
        b += 1
    ans += (1/n)*(0.5**b)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    ans=0
    for i in range(1,N+1):
        temp=1/N
        score=i
        while score<K:
            score*=2
            temp/=2
        ans+=temp
        
    print(ans)
    

main()

Submission status: Accepted

Solution code:
from math import ceil

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

bef = n + 1
ans = 0
div = 1
while k > 0.5:
    a = ceil(k)
    cnt = max(0, bef - a)
    ans += cnt * div
    div /= 2
    k /= 2
    bef = min(n + 1, a)
print(ans / n)

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc126/tasks/abc126_c
import math
N,K = map(int,input().split())
Current_Per = 0
for i in range(1,N+1):
    if i >= K:
        Current_Per += (1/N)
    else:
        Current_Per += ((0.5)**math.ceil(math.log((K/i),2)))*(1/N)

    
print(Current_Per)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
r = 0
for i in range(1,a+1):
  tmp=1/a
  now=i
  while(now<b):
    now*=2
    tmp/=2
    #print(now, b)
  r+=tmp;
print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import *
n, k = map(int, input().split())
r = 0
for i in range(1, n + 1):
    if (i >= k):
        r += n + 1 - i
        break
    r += 1 / 2**ceil(log(k / i, 2))
print(r / n)

Submission status: Accepted

Solution code:
import math

n,k = map(int,input().split(' '))
p = 0

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

print(p)

Submission status: Accepted

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

ans = 0

def calc(x, goal):
    res = 0
    while x < goal:
        x *= 2
        res += 1
    return res    


for i in range(1, N+1):
    cnt = calc(i, K)
    ans += 1 / N * ((1 / 2) ** cnt)

print(ans)

Submission status: Accepted

Solution code:
from decimal import Decimal as d 
n,k=map(int,input().split())
ans=d(0)
for i in range(1,n+1):
    x=d(1)
    if i>=k:
        ans+=d(x)
    else:
        while i<k:
            x=d(x)/d(2)
            i*=2
        ans+=x
print(d(ans)/d(n))

Submission status: Accepted

Solution code:
import math

N,K=map(int,input().split())
p=math.ceil(math.log(K,2))
#print(p)
x=N*(2**p)
#print(x)
s=0

for n in range(1,N+1):
    if n>=K:
        s+=(x//N)
    else:
        q=math.ceil(math.log(K/n,2))
        s+=2**(p-q)
        #print(n,2**(p-q))

print(s/x)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
sum=0.0

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

    sum +=  (1/N)*((1/2)**cnt)
    
    
print(sum)

Submission status: Accepted

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

from math import ceil
cnt = 0
for i in range(1,N+1):
    a = ceil(K/i)
    if bin(a).count("1") == 1:
        b = a.bit_length()-1
    else:
        b = a.bit_length()
    cnt += (1/N)*(0.5**b)
print(cnt)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=[2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]

coin=[]
for i in range(1,n+1):
  if i>=k:
    coin.append(1)
    continue
  for j in range(19):
    if i*d[j] >= k:
      coin.append(0.5**(j+1))
      break
print(sum(coin)/n)

Submission status: Accepted

Solution code:
from collections import Counter

n,k=list(map(int,input().split()))
enum=0
denom=2**20

for pip in range(1,n+1):
    cnt=0
    score=pip
    while score<k:
        score*=2
        cnt+=1
    
    enum+=2**(20-cnt)

print(enum/denom/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())
ans = 0.0
if n >= k:
  ans += (n-k+1)/n
  
for i in range(1, min(n+1, k)):
  now = i
  p = 1/n
  while(now <k):
    now *= 2
    p /= 2
  ans += p
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(pn/n)

Submission status: Accepted

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

def f(x,y):
  cnt = 0
  while x > y:
    y = y << 1
    cnt +=1
  return cnt

ans = 0
for i in range(1,n+1):
  i2 = bin(i)
  cnt = f(k,i)
  ans += 0.5**cnt

print(ans/n)

Submission status: Accepted

Solution code:
from decimal import Decimal 
n, k = map(int, input().split())
count = 0
p = 0

if n >= k:
    a = n
    p += Decimal((a - k + 1) / a)
    n = k
    for i in range(k, 1, -1):
        n = n / i * (i - 1)
        while n < k:
            n *= 2
            count += 1
        p += Decimal(1 / a * (1 / 2) ** count)
    print(p)
else:
    a = n

    while n < k:
        n *= 2
        count += 1
    p += Decimal(1 / a * (1/2) ** count)

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def get_exp(i,m):
    c=0
    while i<m:
        i=i*2
        c+=1
    return c

n,k=map(int,input().split())
r=0
for x in range(1,n+1):
    r+=1/(n*(2**get_exp(x,k)))
    
print(r)

Submission status: Accepted

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

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

print(ans/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from math import ceil, log2

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


n, k = nm()
p = 0
for i in range(1, n + 1):
    if i >= k:
        p += 1 / n
    else:
        num = ceil(log2(k / i))
        p += (1 / n) * (1 / pow(2, num))

print(p)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
import math
from decimal import Decimal
n,k=map(int,input().split())
a=[0]*(n+1)
for x in range(1,n+1):
  a[x] = max(0, math.ceil(math.log(k,2)- math.log(x,2)))
bunsi = 0
for x in range(1,n+1):
  bunsi += 2**(a[1]-a[x])
print(Decimal(bunsi/(n*2**a[1])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

dice_num = 1

def get_prob(dice_num,k):
    i = 0
    while True:
        i += 1
        if i ==1:
            score = dice_num
        else:
            score *= 2
        if score >= k:
            prob = (1/2)**(i-1)
            break
    return prob

prob_all = 0
for i in range(n):
    prob_all += (get_prob(i+1,k))*(1/n)

print(prob_all)

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
l = []
ans = 0

for i in range(1,n+1):
    for j in range(20):
        if 2**j >= k/i:
            l.append(j)
            break

for i in l:
    ans += 1/n * (1/2)**i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = [int(s) for s in input().split()]
N, K = a[0], a[1]
prob = 0
if N > K - 1: prob += (N - K + 1)/N
prob2 = 0
for i in range(1, min(N, K - 1) + 1):
    a = i
    j = 0
    while(a < K): 
        a = a << 1
        j += 1
    prob2 += 1/(2**j)
print(prob + prob2 * (1/N))

Submission status: Accepted

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

res = 0
pi = 1 / n
for i in range(1, n + 1):
    i = k / i
    i = math.log2(i)
    if i <= 0:
        index = 0
    elif int(i) == i:
        index = int(i)
    else:
        index = int(i) + 1
    res += pi / (2 ** index)

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(1, N+1):
    tmp = 0
    check = i
    for j in range(1, 100):
        if check >= K:
            ans += 1 / (N * 2 ** tmp)
            break
        tmp += 1
        check *= 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
ans = 0
N,K = map(int,input().split())
for n in range(1,N+1):
    num = max(0, math.ceil(math.log2(K/n)))
    ans += (1/2)**num

print(ans/N)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

Submission status: Accepted

Solution code:
import math

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

print(ans/n)

Submission status: Accepted

Solution code:
import math
#N = int(input())
#S = str(input())
#A, B = map(int, input().split())
#C = list(map(int, input().split()))

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

ans = 0
for i in range(1, N + 1):
  if i < K:
    tt = math.log2(K/i)
    if tt % 1 == 0:
      time = int(tt)
    else:
      time = int(tt) + 1
    ans += (1 / N) * ((1 / 2) ** time)
  else:
    ans += (1/ N)
#  print(time, ans)
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans=0

baisuu=1
multiplier=0
count=[0]
for i in range(N,0,-1):
    while baisuu*i<K:
        baisuu*=2
        multiplier+=1
        count.append(0)
    
    count[multiplier]+=1

ans=0
for i in range(len(count)):
    ans+=count[i]*0.5**i

ans/=N
print(ans)

Submission status: Accepted

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

for i in range(1, n+1):
    if i<k:
        for j in range(1, 18):
            if i*(2**j) >= k:
                e = j
                break
    else:
        e = 0

    ans += (1/n)*(2**(-e))

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split());result=0
for i in range(1,n+1):
  t=i
  count=0
  while t < k:
    t*=2
    count+=1
  result+=1/n*1/2**count
print(result)

Submission status: Accepted

Solution code:
from math import log2

N,K = [int(i) for i in input().split()]
prob = 0
for i in range(1,N+1):
    j = 0
    while 2**(j) * i < K:
        j += 1
    prob += (1/N) * (0.5)**j
    # print((1/N) * (0.5)**j, j)
print(prob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from fractions import Fraction

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N, K = LI()


kakuritu = []
for i in range(1,N+1):
    count = 0
    while i < K:
        i *= 2
        count += 1
    kakuritu.append(N*(2**count))
result = 0
for kaku in kakuritu:
    result += Fraction(1, kaku)


print(result.numerator / result.denominator)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = {}
p = 0
for i in range(n, 0, -1):
    b = 0
    j = i
    while j < k:
        if j in a:
            b += a[j]
            break;
        else:
            j *= 2
            b += 1
    a[i] = b
c = [0]*20
for i in range(n):
    c[a[i+1]] += 1
for i in range(20):
    p += c[i]*(1/2)**i
print(p/n)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
a = 0

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

print(a)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
a = 0

for n in range(1,N+1):
  c = 0
  while n<K:
    c+=1
    n*=2
  a+=(1/2**c)/N

print(a)

Submission status: Accepted

Solution code:
from math import log2,ceil
n,k=[int(s) for s in input().split()]

sum=0
for t in range(1,n+1):
    if t>=k:
        sum+=1
    else:
        sum+=1/(2**ceil(log2(k/t)))
print(sum/n)

Submission status: Accepted

Solution code:
# for #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion
class union_find:
    def __init__(self, n):
        self.n = n
        self.rank = [0]*n
        self.parent = [int(j) for j in range(n)]
    
    def union(self,i,j):
        i = self.find(i)
        j = self.find(j)
        if self.rank[i] == self.rank[j]:
            self.parent[i] = j
            self.rank[j] += 1

        elif self.rank[i] > self.rank[j]:
            self.parent[j] = i
        else:
            self.parent[i] = j

    def find(self, i):
        temp = i
        if self.parent[temp] != temp:
            self.parent[temp] = self.find(self.parent[temp])
        return self.parent[temp]
from math import log2, ceil
def main():
# Enter your code here. Read input from STDIN. Print output to STDOUT
    n,k = [int(j) for j in input().split()]
    a = max(n-k+1, 0)
    for x in range(1, min(k, n+1)):
        tmp = (1/2)**ceil(log2(k/x))
        # print(tmp,x,ceil(log2(k/x)))
        a+=tmp
    print(a/n)
    # if
    

    # s[k-1] = s[k-1].lower()
    # print("".join(s))
        





        
                # ls[i+1]=
            # base = f
        # print()


        
        




        # l = [int(j) for j in input().split()]




if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(ret)

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
p = [0] * N
for i in range(N):
    n = i + 1
    x = 1 / N
    while n < K:
        x *= 0.5
        n *= 2
    p[i] = x
ans = math.fsum(p)
print(ans)

Submission status: Accepted

Solution code:
import sys
from math import log2
from math import ceil

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, k = MI()
    p = 0
    for i in range(1, min(n+1, k)):
        x = ceil(log2(k/i))
        p += 0.5**x
    p += max(0, n-k+1)
    p /= n
    print(p)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

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

print(cnt / N)

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())
s = 0
for p in range(1, n+1):
    if k > p:
        m = math.ceil(math.log2(-(-k//p)))
        s += 0.5**m
    else:
        s += 1

print(s/n)

Submission status: Accepted

Solution code:
from math import log2,ceil

N,K=map(int,input().split())
SUM=0
for i in range(1,N+1):
  if i<K:
    n_trial = ceil(log2(K/i))
    tmp = 1/(2**n_trial)
  else:
    tmp = 1
  SUM += tmp
print(SUM/N)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import math
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N, K = MI()
    ans = 0
    for n in range(1, N + 1):
        k = math.ceil(math.log2(K / n))
        ans += (1 / N) * min((1 / 2) ** k, 1)

    print(ans)


main()

Submission status: Accepted

Solution code:
import math
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 * pow(0.5, math.ceil(math.log2(K/i)))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for r in range(1, min(K, N+1)):
    x = math.ceil( math.log2(K/r))
    ans += pow(0.5, x) / N
    # print(x, pow(0.5, x) / N)
if K <= N:
    ans += (N - K + 1) / N
print(ans)

Submission status: Accepted

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

ans = []
n_2 = 1 / n
for i in range(1,n+1):
    c = 0
    while i < k:
        c += 1
        i *= 2
    ans.append(n_2*(0.5**c))

print(sum(ans))

Submission status: Accepted

Solution code:
A=list(map(int,input().split()))
N=A[0]
K=A[1]
p=0
for i in range(1,N+1):
    count=0
    while i<=K-1:
        i=i*2
        count=count+1
    p=p+(1/2)**(count)
print(p/N)

Submission status: Accepted

Solution code:
from fractions import Fraction
n,k=map(int,input().split())
times=[0]*n
for i in range(1,n+1):
    count=0
    j=1
    while True:
        if j*i<k:
            count+=1
            j=2*j
        else:
            break
    times[i-1]+=count
ans=0
for k in times:
    ans+=(Fraction(1,2))**k
print(ans.numerator/(ans.denominator*n))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
cnt = 0
for i in range(1,N+1):
    for j in range(100):
        if i * 2**j >= K:
            cnt += 1/2**j
            break
print(cnt/N)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
for i in range(1, N+1):
    prob = 1 / N
    for _ in range(20):
        if i >= K:
            ans += prob
            break
        i *= 2
        prob /= 2
print(ans)

Submission status: Accepted

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

def div_count(n,i):
    ans = i
    count = 0
    while n>ans:
        ans *= 2
        count += 1
    return count
ans = 0
for i in range(1,N+1):
    count = div_count(K,i)
    ans += (1/N) * pow(0.5,count)
print(ans)

Submission status: Accepted

Solution code:
# Problem C - Dice and Coin
# input
N, K = map(int, input().split())

# initialization
ans = 0

def calc_count(n, K):
    tmp = 0
    while n<K:
        tmp += 1
        n *= 2
    return tmp

# count
for i in range(1, N+1):
    count = calc_count(i, K)
    ans += (1 / 2)**count

# output
ans = ans / N
print(ans)

Submission status: Accepted

Solution code:
from math import log2
def solve():
  N, K = map(int, input().split())
  ans = 0
  for i in range(1,N+1):
    if i>=K:
      ans += 1/N
    else:
      a = -(-log2(K/i)//1)
      ans += 1/((pow(2,a))*N)
  return ans
print(solve())

Submission status: Accepted

Solution code:
# 2020/07/23
# AtCoder Beginner Contest 126 - C
import math

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

ans = 0

# Calc
for i in range(1, n+1):
    idx = 1
    wval = i
    while(wval < k):
        wval = wval * 2
        idx = idx + 1
    
    ans = ans + (1/n) * (1/2) ** idx

# Output
print(ans*2)

Submission status: Accepted

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