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:
import math
N,K=map(int,(input().split()))
ans=0
if N >= K :
    for i in range(K-1):
        L = int(math.log(K/(i+1) , 2))
        if L < math.log(K/(i+1) , 2)  :
            ans +=  (1/N) * 0.5**(L+1)
        else:
            ans += (1/N) * 0.5**L
    ans += (N-K+1) / N
else:
    for i in range(N):
        L = int(math.log(K/(i+1) , 2))
        if L - math.log(K/(i+1) , 2) == 0 :
            ans += (1/N) * 0.5**L
        else :
            ans += (1/N) * 0.5**(L+1)
print(ans)

Submission status: Accepted

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

def main():
    N, K = [int(x) for x in input().split()]

    ans = 0

    first = math.ceil(math.log2(K / N))
    num = 2 ** first
    for i in range(N, 0, -1):
        if i >= K:
            ans += 1 / N
            continue
        else:
            first = math.ceil(math.log2(K / i))
            num = 2 ** first
        ans += (1 / N) * (1 / num)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil
n,k = map(int, input().split())
bi = [2**i for i in range(1000)]
ans = 0
for i in range(1,n+1):
    if i >= k:
        ans += 1 / n
        continue
    for j in range(1,k+1):
        if i * bi[j] >= k:
            # print(j, i * 2**j)
            break
    ans += (0.5**j) / n
print('{:.10f}'.format(ans))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
L=[]
for i in range(1,N+1):
  l=0
  while i*2**l<K:
    l+=1
  else:
    L.append(l)
ans=0
for m in range(N):
  ans+=1/N*((1/2)**L[m])
print(float(ans))

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    t = 0
    for i in range(1, n + 1):
        cnt = 0
        ti = i
        while True:
            if ti >= k:
                t += (((1 / 2) ** cnt) * 1 / n)
                break
            else:
                ti *= 2
                cnt += 1
    print(t)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

def win(x):
    prob = 1.0
    while K > x:
        prob /= 2
        x *= 2
    return prob / N

ans = 0.0
for i in range(1, N+1):
    ans += win(i)

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
for i in range(1, n+1):
    tmp = 1.0/n
    now = i
    while now < k:
        now *= 2
        tmp /= 2
    ans += tmp
print("{:.12f}".format(ans))

Submission status: Accepted

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

for i in range(1, N + 1):
    now = i
    temp = 1.0 / N
    while now < K:
        now *= 2
        temp /= 2
    cnt += temp
print(cnt)

Submission status: Accepted

Solution code:
#C
import math

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

data=[[0,1]]
for i in range(1,19):
    data.append([i,2**i])

j=0
while n*data[j][1]<k:
    j+=1

a=0
i=n

while i>=1:
    if i*data[j][1]>=k:
        a+=1/(n*data[j][1])
    else:
        j+=1
        a+=1/(n*data[j][1])
    i-=1

print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
max_multiple_count = 0
max_multiple = 1
while max_multiple < k:
    max_multiple_count += 1
    max_multiple *= 2

if n - k >= 0:
    ans = (n - k + 1)/n
else:
    ans = 0
for i in range(1, min(n+1, k)):
      I = i
      for j in range(1, max_multiple_count+1):
            I *= 2
            if I >= k:
                ans += (1/n) * ((1/2)**j)
                break

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
max_multiple_count = 0
min_multiple_count = 0
max_multiple = 1
min_multiple = min(n, k-1)
while max_multiple < k:
    max_multiple_count += 1
    max_multiple *= 2

if n - k >= 0:
    ans = (n - k + 1)/n
else:
    ans = 0
for i in range(1, min(n+1, k)):
      I = i
      for j in range(1, max_multiple_count+1):
            I *= 2
            if I >= k:
                ans += (1/n) * ((1/2)**j)
                break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = max(N-K+1, 0) / N
for i in range(1, min(N+1, K)):
    c = 0
    while i*2**c < K:
        c += 1
    ans += (0.5**c)/N

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def doubling(i, k):
    while i < k:
        i *= 2
    return i


n, k = map(int, input().split())
p = 0
for i in range(1, n + 1):
    p += (i / doubling(i, k)) / n
print(p)

Submission status: Accepted

Solution code:
from math import ceil

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

Submission status: Accepted

Solution code:
#coding utf-8
import math
N,K=map(int,input().split())
ans=0
A=[]

while(K>0):
  A.append(K)
  if K==1:
    K-=1
  K=math.ceil(K/2)

x=1/N

for i in range(len(A)):
  if N>=A[i] and ans==0:
    ans +=(N-A[i]+1)*x*((1/2)**i)
  elif N>=A[i] and ans>0:
    ans +=(A[i-1]-A[i])*x*((1/2)**i)
  

print(ans)

Submission status: Accepted

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

    ans = 0
    for i in range(1, n + 1):
        t = i
        c = 1
        for j in range(100):
            if t >= k:
                break
            t *= 2
            c += 1
        c -= 1
        ans += (1 / n) * ((1 / 2)**c)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math


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

possibility = 0.0

for i in range(1, N+1):
    tmp_possibility = 1 / N

    cnt = 0

    while i < K:
        i *= 2
        cnt += 1

    tmp_possibility = 1 / N * (0.5 ** cnt)

    possibility += tmp_possibility

print(possibility)

Submission status: Accepted

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

result=0.0

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

Submission status: Accepted

Solution code:
def test():
    n,k = map(int,input().split())
    a = []; ans = 0
    for i in range(1,n+1):
        result = i
        count = 1
        while result < k:
            result *= 2
            count /= 2
        ans += count
    print("{:.12f}".format((1/n)*ans))



if __name__ == "__main__":
    test()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, k = LI()

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



print(ans / n)

Submission status: Accepted

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

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:
    temp=math.ceil(math.log2(k/i))
    #print(temp)
    ans+=0.5**temp
  else:
    ans+=1
print(ans/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f_c():
    n, k = map(int, input().split())
    a = 0
    for i in range(1, n+1):
        c, v = 0, i
        while True:
            if v>=k:
                break
            c, v = c+1, v*2
        a += (1/n)*(1/2)**c
    print(a)

if __name__ == "__main__":
    f_c()

Submission status: Accepted

Solution code:
me,goal = map(int,input().split())
probabilities = []

ans = 0
for i in range(1,me+1):

    t = 0
    while True:
        if i>=goal:
            ans += (1/2**t)/me
            break

        i *= 2
        t += 1

print(ans)

Submission status: Accepted

Solution code:
import math
eps = 10**(-8)
N,K = map(int,input().split())
L = min(N,K-1)
cnt = 0
for i in range(1,L+1):
    a = math.log(K/i)/math.log(2)
    if abs(a-round(a))<eps:
        a = round(a)
    else:
        b = int(a)
        if a>b+eps:
            a = b+1
        else:
            a = b
    cnt += 2**(-a)
print(max(1-(K-1)/N,0)+cnt/N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

ans=0
for i in range(N):
  temp=1/N*0.5**math.ceil(math.log2(K/(i+1))) if i+1<K else 1/N
  ans+=temp
  #print(temp)

print(ans)

Submission status: Accepted

Solution code:
#C - Dice and Coin(ABC126)
N,K=map(int, input().split())
ans=0
m=0
for i in range(1,N+1):
    if i<=K:
        m=0
        n=i*(2**m)
        while n<K:
            m+=1
            n=i*(2**m)
        ans+=(1/(N*(2**m)))
    else:
        ans+=(N-K)/N
        break
print(ans)

Submission status: Accepted

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

print(prob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    N,K = map(int,input().split())
    ans = 0
    for i in range(1,N+1):
        n = 0
        while i < K:i*=2;n+=1
        ans += ((1/N)*(1/2)**n)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    N,K = map(int,input().split())
    ans = 0
    for i in range(1,N+1):
        tmp = i
        n = 0
        while tmp < K:tmp*=2;n+=1
        ans += ((1/N)*(1/2)**n)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

P = 0
P_log2 = 1

for i in range(1, N+1):
    if i < K:
#         T = int(math.log2(K / i)) + 1
        T = math.ceil(math.log2(K / i))
        P += 1/ N * 1 / (2 ** T)
#         print(i, T)
    else:
        P += 1 / N
# P += 1/ N * 1 / (2 ** P_log2)
            
print(P)

Submission status: Accepted

Solution code:
from itertools import accumulate
import sys
from heapq import heappush, heappop
import math


def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    p = 0
    for n in range(1, N+1):
        c = max(math.ceil(math.log2(K / n)), 0)
        p += 1 / N * 0.5 ** c
    print(p)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
Klist = []
temp = K
ans = 0
amari = 0

#Klist作成
while temp>=1:
    Klist.append(temp)
    temp = -(-temp//2)
    if temp==1:
        Klist.append(temp)
        break

powcount = 0
#powcount導出
while True:
    if N >= Klist[powcount]:
        amari = N - Klist[powcount]
        break
    powcount += 1
    
for i in range(powcount,len(Klist)):
    if i==powcount:
        ans += (N-Klist[powcount]+1)/pow(2,powcount)
        #print(i,ans)
    else:
        ans += (Klist[i-1]-Klist[i])/pow(2,i)
        #print(i,ans)
        
print(ans/N)

Submission status: Accepted

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

res = 0.0

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

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

count = 0
max_count = math.ceil(math.log2(k))
total = n * (2 ** max_count)

for i in range(1, n+1):
    if k >= i:
        t = math.ceil(math.log2(k/i))
        count += 2 ** (max_count - t)
    else:
        count += 2 ** max_count

print(count / total)

Submission status: Accepted

Solution code:
import sys
n,k = map(int,input().split())
if k == 1:
    print(1)
    sys.exit()
a = n
n0 = n
i = 0
sum = 0
power_list = [0] * 24
if n > k:
    power_list[0] = n - k + 1
    n = k - 1
    a = k 
i = 1
a = k
while a != 1:
    if a % 2 == 0 and a//2 > n:
        a = a//2
        k = a
        i += 1
    elif a % 2 == 0 and a//2 <= n:
        power_list[i] = n - a//2 + 1
        n = a//2 - 1
        a = a//2
        i += 1
    else:
        a += 1
for i in range(24):
    sum += (1/2)**i * power_list[i] / n0
#print(power_list)
print(sum)

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:
        t = math.ceil(math.log2(K/i))
        ans += (0.5)**t / N
    else:
        ans += 1 / N

print(ans)

Submission status: Accepted

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

if N <= K-1: 
  for i in range(1, N+1):
    katsu += 0.5 ** ((math.log2((K-1) / i) // 1)+1) 
  print(katsu/N)
  exit()
else: 
  for i in range(1, K):
    katsu += 0.5 ** ((math.log2((K-1) / i) // 1)+1) 
  for i in range(K, N+1):
    katsu += 1
  
  print(katsu/N)
  exit()

Submission status: Accepted

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


l = []
for i in range(1,n+1):
    ct = 0
    while i < k:
        ct += 1
        i *= 2
    l.append(0.5**ct)
    
print(sum(l)/n)

Submission status: Accepted

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

while True:
  a /= 2
  l.append(a)
  if a <= 1:
    break

def sum_num(x):
  sum_temp = 0
  for i in range(1, x):
    for j in range(len(l)):
      if l[j] <= i:
        sum_temp += 0.5**(j+1)
        break
  return sum_temp

if n < k:
  ans_temp += sum_num(n+1)
else:
  ans_temp += sum_num(k) + (n - k + 1)

print(ans_temp / n)

Submission status: Accepted

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

Submission status: Accepted

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

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

            point *= 2
            count += 1
        ans += (1/n)*((1/2)**count)

print(ans)

Submission status: Accepted

Solution code:
while True:
    try:
        n, k = map(int, input().split())
        ans = 0
        for num in range(1, n+1):
            count = 0
            while True:
                if num >= k:
                    break
                else:
                    num *= 2
                    count += 1
            ans += 1 / 2**count
        print(ans/n)
    except:
        break

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, K: int):
    l = [(1 / 2) ** max(0, math.ceil(math.log2(K / i))) for i in range(1, N + 1)]
    print(sum(l) / len(l))
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, K = map(int, input().split())
        
    prob = 0
    
    for i in range(1, N+1):    
        for n in range(1000):
            if K <= i*2**n:
                num = n
                break
        
        prob += (1/N)*((1/2)**num)
    print(prob)

Submission status: Accepted

Solution code:
import math
while True:
    try:
        N, K = map(int, input().split())
        
        P = 0
        if K <= N:
            P = (N-K+1) / N
            
        for i in range(1, min(K, N+1)):
            p = math.ceil(math.log2(K/i))
            P += (1/N) * (0.5**p)
        print(P)
    except:
        break

Submission status: Accepted

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

ans = Decimal(0)
m = n+1

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

Submission status: Accepted

Solution code:
import math

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

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

print(res)

Submission status: Accepted

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

print(calc)

Submission status: Accepted

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

preans = 0
j = 1

for i in range(1, n + 1):
    if i >= k:
        preans += 1
    else:
        while i * (2 ** j) < k:
            j += 1
        preans += 1 / (2 ** j)
        j = 1

ans = preans / n

print(ans)

Submission status: Accepted

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

def timesNeed(S0, K):
    return int(math.ceil(math.log2(K)-math.log2(S0)))

def solve(N: int, K: int):
    fact = 1./N
    p = 0.
    for S0 in range(1, min(N, K-1)+1):
        p += math.pow(0.5, timesNeed(S0, K))
    p *= fact
    p += max(0., (N-K+1)/N)
    print(p)
    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))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

sum = 0
for i in range(1,n+1):
    tmp = 1/n
    score = i
    while(score <= k-1 and score >= 1):
        score *= 2
        tmp *= 0.5
    sum += tmp
print(sum)

Submission status: Accepted

Solution code:
from math import ceil, sqrt, log2

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

answer = sum(map(lambda x: 0.5 ** ceil(log2(k / x)) if x < k else 1, range(1, n + 1))) / n
print(answer)
# 対数わからない・・

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
ttl = 0
res = []
for i in range(1,n+1):
  ttl = i
  cnt = 0
  while True:
    if ttl >= k:
      break
    ttl = ttl*2
    cnt+=1
  p = 0.5**cnt
  res.append(p)
ans = sum(res)/n
print(float(ans))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
nk=list(map(int,input().split()))
a=0
for i in range(1,nk[0]+1):
    if i>=nk[1]:
        a+=1
    else:
        p=math.ceil(math.log(nk[1]/i, 2))
        a+=1/(2**(p))
print(a/nk[0])

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
pro = 0.0
for i in range(1, N + 1):
    mul = i
    count = 0
    while mul < K:
        mul *= 2
        count += 1
    pro += (1 / N) * ((1 / 2) ** count)
print('{:.10f}'.format(pro))

Submission status: Accepted

Solution code:
import math

N, K = map(int, input().split())
ans = 0
l = [2**i for i in range(18)]

for j in range(1, N+1):
    for k in l:
        if j*k >= K:
            ans += (1/N)*0.5**math.log2(k)
            break
print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

j = 0

while k > 2 ** j:
    j += 1

jl = [j]

for i in range(2, n+1):
    p = jl[i - 2]
    if k <= i:
        p = 0
    else:
        while True:
            p -= 1
            if k > i * (2**p):
                p += 1
                break
    jl.append(p)

ans = 0

for j in jl:
    ans += 2**(-j) / n

# print(jl)
print(ans)

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
nums = [k]
while True:
    a = math.ceil(nums[-1] / 2)
    nums.append(a)
    if a == 1:
        break

max_e = len(nums) - 1
m = n
res = 0
for i, a in enumerate(nums):
    if m >= a:
        res += (m - a + 1) * 2**(max_e - i)
        m = a - 1
print(res / (n * 2**max_e))

Submission status: Accepted

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

acc = 0
for dice in range(1, n+1):
    score = dice
    coin_count = 0
    while score < k:
        score *= 2
        coin_count += 1
    acc += 0.5 ** coin_count / n

print(acc)

Submission status: Accepted

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

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

    print(ans)


main()

Submission status: Accepted

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

import math
sums = 0
for i in range(1,N+1):
    num=int(math.log(K/i,2)+1)
    
    if i>K-1:
        sums +=(1/N)
    else:
        if i*2**(num)>=K>i*2**(num-1):
            sums += 1/(N * math.pow(2,num))
        else:
            sums += 1/(N * math.pow(2,num-1))

print(sums)

Submission status: Accepted

Solution code:
def calc_log2(x, y, cnt):
    if x >= y: return cnt
    return calc_log2(x * 2, y, cnt + 1)

def calc_power(num, acc):
    if num == 0: return acc
    else: return calc_power(num - 1, acc * 2)

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

max_log2 = calc_log2(1, k, 0)

li = [0] * n
molecure = 0
for i in range(n):
    molecure += calc_power(max_log2 - calc_log2(i + 1, k, 0), 1)

denominator = n * calc_power(max_log2, 1)

print(float(molecure) / denominator)

Submission status: Accepted

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

ans=0

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

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

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
ans = 0
if K <= N:
    ans += (1/N)*(N-K+1)
    dp = [0] + [1/N] * K
else:
    dp = [0] + [1/N] * N + [0] * (K-N)
for i in range(1,K):
    if i % 2 == 0:
        dp[i] += dp[i//2] * (1/2)
if K % 2 == 0:
    ans += sum(dp[K//2:K])*(1/2)
else:
    ans += sum(dp[K//2+1:K])*(1/2)
print(ans)

Submission status: Accepted

Solution code:
def coin(i,k):
    count = 0
    while i < k:
        i = i * 2
        count += 1
    return count
 
n, k = map(int, input().split())
sum = 0
coin_count = 0
 
 
for i in range(1,n+1):
    x = coin(i, k)
    sum += (1/n) * ((0.5) ** x)
 
print(sum)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,K = map(int, input().split())
ans = 0
for i in range(1,N+1):
	coin = 0
	point = i
	if K <= i:
		ans += 1/N
	else:
		while point < K:
			point *= 2
			coin += 1
		ans += (1/N) * (0.5)**coin

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def cul(K, n):
    i = 0
    while n < K:
        n = n*2
        i += 1
    return 1/(2**i)

ans = 0
for n in range(1, N+1):
    ans += (1/N) * cul(K, n)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def nankai(Me):
    cnt = 0
    for j in range(20):
        if K-1 >= Me*(2**j):
            cnt +=1
        else: break
    return cnt

      
N, K = map(int,input().split())
P=[(1/N)*(1/2)**nankai(i) for i in range(1,N+1)]
print(sum(P))

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
#まずサイコロでN通り
#表が何回あればいいか考える((k-1)//2+1)
#裏が出たら負け
p=0
for i in range(1,n+1):
    if k//i==0:
        p+=1/n
    elif k%i!=0:
        p+=((1/2)**(int(math.log2(k//i)+1)))/n
    elif 2**int(math.log2(k//i))!=k//i:
        p+=((1/2)**(int(math.log2(k//i)+1)))/n
    else:
        p+=((1/2)**(int(math.log2(k//i))))/n

print(p)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
ite = 0
for i in range(1, N+1):
    for j in range(10**5):
        if K <= i*2**j:
            ite = j
            break

    ans += (1/N) * (1/2)**ite

print(ans)