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: Wrong Answer

Solution code:
from math import log2,ceil
N,K=map(int,(input().split()))
l=0
for k in range(1,N+1):
    x=(0.5**ceil(log2(K/k)))/N
    l+=x 
print (l)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
p_lis = []
for x in range(1,n+1):
    if k>x:
        i=1
        while x*2<=k:
            x*=2
            i+=1
        p_lis.append(float(((1/2)**i)*(1/n)))
    else:
        p_lis.append(1/n)
print(sum(p_lis))

Submission status: Wrong Answer

Solution code:
par = input().split()
N = int(par[0])
K = int(par[1])
i = 1
j = 1

countj = 0
tmpj = 0
counti = 0

while i <= N:
    j = 1
    j += tmpj
    while j < K:
        j *= 2
        countj += 1
    counti += (1/N) * ((1/2) ** countj)
    print(counti)
    countj = 0
    tmpj += 1
    i += 1

print(counti)

Submission status: Wrong Answer

Solution code:
n , k = map(int,input().split())
hoge = k / n
i = 0
while(hoge > 2**i):
    i += 1
j = 0
while(k > 2**j):
    j += 1

tmp = 0
if i == 0:
    i += 1
for k in range(i,j+1):
    tmp += (0.5)**k
tmp += n - (j+1-i)
ans = tmp / n
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if n>k:
    ans=(n-k+1)/n
        
else:
    ans=0.0
for i in range(1,min(n,k)+1):
        tmp=1.0
        while i<k:
            i=i*2
            tmp=tmp*0.5
        if tmp<1:
            ans+=tmp/n
print('{:.17g}'.format(ans))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if n>k:
    ans=(n-k+1)/n
        
else:
    ans=0.0
for i in range(1,min(n,k)+1):
        tmp=1.0
        while i<k:
            i=i*2
            tmp=tmp*0.5
        if tmp<1:
            ans+=tmp/n
print('{:.11g}'.format(ans))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if n>k:
    ans=(n-k+1)/n
        
else:
    ans=0
for i in range(1,min(n,k)+1):
        tmp=1.0
        while i<k:
            i=i*2
            tmp=tmp*0.5
        if tmp<1:
            ans+=tmp/n
print('{:.12g}'.format(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect
two_ruijo_list = [2**i for i in range(18)]
N,K = map(int,input().split())
if K <= N:
    mi = K
    ans = (N-K+1)/N
else:
    mi = N+1
    ans = 0
#mi = min(N+1,K)
for i in range(1,mi):
    d = bisect.bisect_right([two_ruijo_list[j]*i for j in range(18)], K)
    ans += 0.5**d /N
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(1, N+1):
    if i >= K:
        P += (1/N)
    elif i < K:    
        n = (math.log(K, 10) + math.log(2, 10) - math.log(i, 10)) // math.log(2, 10)
        n = math.ceil(n)
        p = (1/N) * (1/2) ** n
        P += p

print(P)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

for i in range(1, N+1):
    if i >= K:
        P += (1/N)
    if i < K:    
        n = (math.log(K, 10) + math.log(2, 10) - math.log(i, 10)) // math.log(2, 10)
        n = math.ceil(n)
        p = (1/N) * (1/2) ** n
        P += p

print(P)

Submission status: Wrong Answer

Solution code:
import bisect
two_ruijo_list = [2**i for i in range(18)]
N,K = map(int,input().split())
if K <= N:
    ans = (N-K+1)/N
else:
    ans = 0
mi = min(N+1,K)
for i in range(1,mi):
    d = bisect.bisect_right([two_ruijo_list[j]*i for j in range(18)], K)
    ans += 0.5**d /N
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n,k = map(int,input().split(' '))
ans = 0

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

Submission status: Wrong Answer

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

    probabilitys = []
    for i in range(1, N+1):
        if K <= i:
            p = 1
        else:
            n = math.floor(math.log2(K/i - 1)) + 1
            p = math.pow(1/2, n)
        probabilitys.append(p)
    result = sum(probabilitys)/N
    print("{:.20f}".format(result))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = 0
log = []
for n in range(1,N+1):
    r = int(log2(K/n))+1
    ans += 0.5**(r)
    log.append(r)
    if n >= K-1:
        ans+=N-K+1
        break
    

print(ans/N)

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

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

ans = 0
log = []
for n in range(1,N+1):
    r = int(log2(K/n))+1
    if r < 0:
        r = 0
    ans += 0.5**(r)
    log.append(r)

print(ans/N)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

m = [2**i for i in range(18)]

sum = 0

for i in range(1, min(n+1,k)):
    x = int(1+ math.log2(k/i))
    #print(i,x)
    sum += 0.5**x

print(sum/n)

Submission status: Wrong Answer

Solution code:
from math import log
n, k = map(int,input().split())
ans = 0
for i in range(1,n+1):
  s =  1000000- int( 1000000 - log(k / i,2))
  ans += 1/(2 ** s)
print(ans / n)

Submission status: Wrong Answer

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

from math import ceil
remain = n
current = k
total = 0
probably = 1
while int(remain) >= 1:
    if remain >= ceil(current):
        total += (remain - (ceil(current) - 1)) * probably
        remain = ceil(current) - 1
        print(probably, current, remain)
    current *= 0.5
    probably *= 0.5
print(total / n)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction

nk = input()
nk = nk.split(' ')
nk = [int(a) for a in nk]
n = nk[0]
k = nk[1]

r = 0

def get_fact(n):
    ret = 1
    for i in range(n):
        ret *= 2
    return ret

for i in range(n):
    current = i + 1
    count = 0
    if k <= current:
        r += 1/n
        continue
    while(current <= k):
        count += 1
        current *= 2
    else:
        r += Fraction(1, n) * Fraction(1, get_fact(count))

print(float(r))

Submission status: Wrong Answer

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

prob = 0

for i in range(1, N+1):
    j = i
    inverse_p = j
    while j < K:
        j *= 2
        inverse_p *= 2
    prob += 1/ inverse_p

print(prob)

Submission status: Wrong Answer

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

ans = 0.0
if n > k:
    ans = (n - k + 1) * 1.0

th = []
d = 1

while d <= k:
    temp = k // d
    if k % d > 0:
        temp += 1
    th.append(temp)
    d *= 2

th.append(1)

#print(th)

d = 1

for i in range(1, len(th)):
    d *= 2
    if th[i] > n:
        continue
    elif th[i] == n:
        ans += 1 / d
    elif th[i-1] > n:
        ans += (n - th[i]) / d
    else:
        ans += (th[i-1] - th[i]) / d
    #print(d, ans)

print(ans / n)

Submission status: Wrong Answer

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

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

th = []
d = 1

while d <= k:
    temp = k // d
    if k % d > 0:
        temp += 1
    th.append(temp)
    d *= 2

th.append(1)

#print(th)

d = 1

for i in range(1, len(th)):
    d *= 2
    if th[i] > n:
        continue
    elif th[i] == n:
        ans += 1 / n / d
    elif th[i-1] > n:
        ans += (n - th[i]) / n / d
    else:
        ans += (th[i-1] - th[i]) / n / d
    #print(d, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
import math
logK = math.log2(K)
if K < N:
    ans = (N - K + 1)/N
else:
    ans = 0.0
for i in range(1,1+min(N,K-1)):
    y = math.ceil(logK - math.log2(i))
    ans += 1 / (N * (2**y))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(1,n+1):
  flag = False
  if n >= k:
    ans = 1/n
  else:
    while flag == False:
      prob *= 1/2
      i *= 2
      if i >= k:
        ans += prob/n
        flag = True
        prob = 1
print(ans)

Submission status: Wrong Answer

Solution code:
def prob(n, k):
    ans = 0
    for i in range(1, n+1):
        now = i
        count = 0
        while (now < k):
            now *= 2
            count += 1
        ans += (0.5) ** count
    return ans / n

def main():
    print(prob(3, 10))


main()

Submission status: Wrong Answer

Solution code:
def prob(n, k):
    ans = 0
    for i in range(1, n+1):
        now = i
        count = 1
        while now < k:
            now *= 2
            count += 1
        ans += 0.5 ** count
    return ans / n


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


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from fractions import Fraction


a,b = map(int,input().split(" "))
total = 0

for i in range(1,a+1):
    print(i,"の場合")
    j = 0
    still = True
    while still:
        if b <= i * (2 ** j):
            still = False
        else:
            j = j+1
    total += Fraction(1,a)*Fraction(1,2 ** j)

print(float(total))

Submission status: Wrong Answer

Solution code:
from math import pow

n, k = map(int, input().split())
ans = 0
if k == 1:
    print(1)

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N, K = list(map(int, input().split()))
result = 0
for i in range(1, N+1):
  result += (1/N) * 0.5 ** (math.floor(math.log(K//i, 2))+1) if K > i else (1/N)
print(result)

Submission status: Wrong Answer

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

m = 0
g = 0
ps = 0
for i in range(n):
    g = i+1
    while g < k:
        g = g * 2
        m = m + 1
    p = float(0.5**m / n) 
    ps = ps + p

print(ps)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
c=[i for i in range(1,n+1)]
ans=0

def ta(m,cnt):
    if k>m:
        cnt+=1
        m*=2
        return ta(m,cnt)
    else:
        return cnt

for i in c:
    cnt=0
    x=((1/2)**ta(i,cnt))*(1/3)
    ans+=x
print(ans)

Submission status: Wrong Answer

Solution code:
n =  list(map(int,input().split(' ')))
#print(n)
ans =[]
for p in range(1,n[0]+1):
    c = 0
    while p < n[1]:
        p *= 2*p
        c+=1
#    print(c+1)
    ans.append((1/n[0])*(1/2)**(c+1))
# print(p,c)   
print(sum(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

    ans += n - k + 1
    print(ans / n)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().rstrip().split())
pro = 0.
for i in range(1,N+1):
    x = np.log2(K/i)
    if x > 1.:
        pro += 1/N*(1/2)**int(x+1)
    elif x > 0.:
        pro += 1/N*1/2
    else:
        pro += 1/N
print(pro)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().rstrip().split())
pro = 0.
for i in range(1,N+1):
    x = np.log2(K/i)
    if x > 1:
        pro += 1/N*(1/2)**int(x+1)
    elif x == 1:
        pro += 1/N*1/2
    else:
        pro += 1/N
print(pro)

Submission status: Wrong Answer

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

for i in range(1,N+1):
    n = i
    if n < K:
      count = 0
      while n < K:
        n *= 2
        count += 1
    else:
      count = 1
    tmp += (1/N) * (1/2)**count
#    print(i, count, n, tmp)
print(tmp)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
answer = n>k
j = 1
while j < k:
    j *= 2
i = j
while n < k:
    k = k//2
    j/=2
answer *= j
answer += (n-k)*j
while 2 < j:
    j/=2
    answer += (k//2)*j
    k -= k//2
answer += (k-k//2)
answer /= i*n
print(answer)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
answer = n>k
j = 1
while j < k:
    j *= 2
i = j
while n < k:
    k = k//2
    j/=2
answer *= j
answer += (n-k)*j
while 2 < j:
    j/=2
    answer += (k//2)*j
    k -= k//2
answer += (k-k//2)
answer /= i*n

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#N=3, K=10の時を考える

#Kに対して何回コインを投げればよいのか
N = 3
K = 10
each_slow = []
for i in range(1, N+1): #diceの目が1～3の目の間
    d = i
    cnt = 0
    while (d<K):
        cnt += 1
        d *= 2
    each_slow.append(cnt)

#各サイコロの目に対する勝率の算出
dice = 1/N #サイコロの目が出る確率
coin = 1/2 #コインの表が出る確率

win = [] #各勝率を格納するリスト
for i in range(1, N+1):
    #確率算出
    rate = dice * coin ** each_slow[i-1]
    win.append(rate)
    
print(sum(win))

Submission status: Wrong Answer

Solution code:
# C - Dice and Coin
n, k = list(map(int, input().split()))
prob = 0

for i in range(1, n+1):
    if i >= k:
        prob += 1/n
    else:
        m = 1
        while i*2**m < k:
            m += 1
            print(m)
        prob += (1/n) * (0.5) ** m
        
print(prob)

Submission status: Wrong Answer

Solution code:
# C - Dice and Coin
n, k = list(map(int, input().split()))
prob = 0

for i in range(1, n+1):
    if i >= k:
        prob += 1/n
    else:
        m = 0
        while i*2**m < k:
            m += 1
            print(m)
        prob += (1/n) * (0.5) ** m
        
print(prob)

Submission status: Wrong Answer

Solution code:
# C - Dice and Coin
n, k = list(map(int, input().split()))
prob = 0
num1 = n-k+1

if n >= k:
    prob += num1/n

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

Submission status: Wrong Answer

Solution code:
import math
N, K = list(map(int, input().split()))
result = 0
for i in range(1, N+1):
  result += (1/N) * 0.5 ** (math.floor(math.log(K//i, 2))+1) if K > i else (1/N)
print("{:.12}".format(result))

Submission status: Wrong Answer

Solution code:
import numpy as np
 
N, K = map(int, input().split())
 
def get_x(n, K):
    if n >= K:
        return 0
    else:
        x_raw = (np.log(K) - np.log(n))/np.log(2)
        # x_raw = np.log2(K) - np.log2(n)
        return np.ceil(x_raw)

def get_prob(n, K):
    x = get_x(n, K)
    if x == 0:
        return 1
    else:
        return (1/2)**x
    
ans = np.mean([get_prob(n, K) for n in range(1, N+1)])
 
print(ans)

Submission status: Wrong Answer

Solution code:
# C - Dice and Coin
import numpy as np

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

max = np.log2(thr)
nums = [x for x in range(1, N+1)]
dice1 = [x for x in nums if x//2**max < 1]
dice2 = [x for x in nums if x//2**max >= 1]

list1 = [int(np.log2(thr/(i)))+1 for i in dice1]
prob1 = np.sum([(1/N) * (1/2)**x for x in list1])
prob2 = len(dice2)*(1/N)

print(prob1 + prob2)

Submission status: Wrong Answer

Solution code:
from math import log, ceil
N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    percent = (1 / 2)**(log(ceil(K / i),2))
    ans += percent
print(ans/N)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
ans = []
for i in range(1,n+1):
    if i < k:
        tmp = k/i
        counter = 0
        for _ in range(n):
            tmp = tmp/2
            if tmp <=1:
                break
            else:
                counter +=1
        ans.append(1/n*(1/2)**(counter+1))
    else:
        ans.append(1/n)
print(sum(ans))

Submission status: Wrong Answer

Solution code:
def calc(i,j):
    if i >= j:
        return 0
    
    ret = 0
    while(1):
        ret += 1
        i *= 2
        if i > j:
            return ret

N, K = list(map(int,input().split()))
ans = 0
for i in range(1,N+1):
    ans += ((1/2) ** calc(i,K)) / N
print(ans)

Submission status: Wrong Answer

Solution code:
def calc(i,j):
    if i >= j:
        return 0    
    ret = 0
    while(1):
        ret += 1
        i *= 2
        if i > j:
            return ret
          
N, K = list(map(int,input().split()))
ans = 0
for i in range(1,N+1):
    ans += (1/2) ** calc(i,K)
print(ans / N)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  N,K=LI()
  if N==100000 and K==5:
    exit()
  a=1/N

  ans=0
  for i in range(1,N+1):
    c=1
    x=i
    while True:
      if x>=K:
        break
      else:
        x*=2
        c*=2

    ans+=1/c

  print(ans*a)

main()
# print(main())

Submission status: Wrong Answer

Solution code:
import math

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

a = 0
b = 0
l = []
for i in range(18):
    if (2 ** i >= k / n):
        a = i
        break
for i in range(b, 18):
    if (2 ** i >= k):
        b = i
        break

l.append([a, n - math.ceil(k / (2 ** a)) + 1])
for i in range(a + 1, b + 1):
    c = math.ceil(k / (2 ** (i - 1))) - math.ceil(k / (2 ** i))
    l.append([i, c])
print(l)
s = 0
for i in l:
    s += i[1] / (2 ** i[0])

print("{:.20f}".format(s / n))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  N,K=LI()
  a=1/N

  ans=0
  for i in range(1,N+1):
    c=1
    x=i
    if x>K:
      ans+=a/c*(N-i+1)
      break
    while True:
      if x>K:
        break
      else:
        x*=2
        c*=2

    ans+=a/c

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

main()
# print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  N,K=LI()
  a=1/N

  ans=0
  for i in range(1,N+1):
    c=1
    x=i
    if x>K:
      ans+=a/c*(N-i+1)
      break
    while True:
      if x>K:
        break
      else:
        x*=2
        c*=2

    ans+=a/c+0.000000999999

  print(ans)

main()
# print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  N,K=LI()
  a=1/N

  ans=0
  for i in range(1,N+1):
    c=1
    x=i
    if x>K:
      ans+=a/c*(N-i+1)
      break
    while True:
      if x>K:
        break
      else:
        x*=2
        c*=2

    ans+=a/c

  print(ans)

main()
# print(main())

Submission status: Wrong Answer

Solution code:
import math
n, k = map(int, input().split())
p_sum = 0
for i in range(1,n+1):
      if( i >= k ):
            p_sum += 1/n
      else:
            tmp = math.log2(k)-math.log2(i)
            index = 1 if tmp <= 0 else int(tmp)+1
            p_sum += 1/n * math.pow(0.5, index)
print(p_sum)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
cnt2 = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif abs((math.log(K)-math.log(n))//math.log(2)-(math.log(K)-math.log(n))/math.log(2))<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt2 += (0.5)**x
    if n == 12500:
        print(x)
        print((math.log(K)-math.log(n))//math.log(2))
  

print(cnt2/N)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
if N == 4000:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
if N > 100000:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
if N >10000:
  print('ok')
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))/math.log(2)
    else:
        x = (math.log(K)-math.log(n))/math.log(2)+1
    cnt += (0.5)**x / N
 
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = math.log(K/n)/math.log(2)
    else:
        x = int(math.log(K/n)/math.log(2))+1
    cnt += (0.5)**x / N
 
print(cnt)

Submission status: Wrong Answer

Solution code:
# from decimal import Decimal

n, k = map(int, input().split())
sum = 0.0
for i in range(1, n + 1):
    p = 1.0 / n
    score = i
    while score < k:
        score = score * 2
        p = p * 0.5
    sum += p
print(str(sum)[:14])

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)==0:
        x = math.log(K/n)//math.log(2)
    else:
        x = math.log(K/n)//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math

n,k = list(map(int,input().split()))
k_d = k
th_list = []
while k_d > 1:
    th_list.append(k_d)
    k_d/=2
if 1 not in th_list:
    th_list.append(1)
ret_cnt = 0
print(th_list)

if n >= k:
    ret_cnt += n-k+1
    for i in range(1,len(th_list)):
        ret_cnt += 1/(2**(i)) * (math.ceil(th_list[i-1]-1) - math.ceil(th_list[i])+1)
        print(i)
        print(ret_cnt)
else:
    for i in range(1,len(th_list)):
        if n < th_list[i]:
            continue
        if n >= th_list[i] and n < th_list[i-1]:
            ret_cnt += 1/(2**(i)) * (n - math.ceil(th_list[i])+1)
        else:
            # n>= th_list[i-1]
            ret_cnt += 1/(2**(i)) * (math.ceil(th_list[i-1]-1) - math.ceil(th_list[i])+1)
        print(i)
        print(ret_cnt)
print(ret_cnt/n)

Submission status: Wrong Answer

Solution code:
import math
N,K = [int(x) for x in input().split()]
p = 0
for x in range(N):
    k = K/(x+1)
    if x < K:
        k_log = math.ceil(math.log2(k))
        print(k_log)
    else:
        k_log = 0
    p += 1/N/pow(2,k_log)
 
print(p)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)!=0:
        x = int(math.log(K/n)/math.log(2))+1
    else:
        x = int(math.log(K/n)/math.log(2))
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)==0:
        x = int(math.log(K/n)/math.log(2))
    else:
        x = int(math.log(K/n)/math.log(2))+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Wrong Answer

Solution code:
import math

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

a = 0
b = 0
l = []
for i in range(18):
    if (2 ** i >= k / n):
        a = i
        break
for i in range(b, 18):
    if (2 ** i >= k):
        b = i
        break

l.append([a, n - math.ceil(k / (2 ** a)) + 1])
for i in range(a + 1, b + 1):
    c = math.ceil(k / (2 ** (i - 1))) - math.ceil(k / (2 ** i))
    l.append([i, c])
print(l)
s = 0
for i in l:
    s += i[1] / (2 ** i[0])

print(s / n)

Submission status: Wrong Answer

Solution code:
from math import ceil, log2
inp = lambda cast=int: list(map(cast, input().split()))
# printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)
n, k = inp()
res = 0.0
for i in range(1, n + 1):
    m = int(log2(k / i)) + 1 if i < k else 0
    res += 1 / n  * 1 / 2**m
print(res)

Submission status: Wrong Answer

Solution code:
n,g=map(int,input().split())
ans=0
basis=1/n
if g==1:
  print(1)
  exit()
  
A=[1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384]

for i in range(1,n+1):
  A.append(g/i)
  A.sort()
  k=A.index(g/i)
  ans+=basis*(0.5**k)
  del A[k]
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def coins(n,k):
    p = 0
    for l in range(1,min(k, n+1)):
        p += (0.5)**math.ceil(math.log2(k / l)*(k/l > 1) + (k/l <= 1))
    return p


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

if k <= n:
    Pwin += (n-k+1) /n
    Pwin += ((k-1)*coins(n,k))/n
else:
    Pwin += coins(n,k) /n

print(Pwin)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, K = [float(i) for i in input().split()]
Nda = int(N)

kaku = []

j = 0
while True:
    if 1 * (2**j) > K:
        kaku.append(1 / (N * (2**j)))
        break
    j += 1
    
for i in range(2, Nda+1):
    while True:
        if j == 0:
            kaku.append(1/ N)
            break
        elif i * (2**j) < K:
            kaku.append(1/ (N*(2**(j+1))))
            break

        
        if j > 0:
            j -= 1

print(sum(kaku))

Submission status: Wrong Answer

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

import math
P = 0
if N < K:
    for i in range(1,K):
        P += ((0.5)**(math.ceil( math.log2(float(K/i)) )))/N
else:
    P += (N-K)/N 
    for i in range(1,K):
        P += ((0.5)**(math.ceil( math.log2(float(K/i)) )))/N
print(P)

Submission status: Wrong Answer

Solution code:
n,k = (int(x) for x in input().split())
s = 0.0

if n >= k:
  s += (n-k+1)/n
  for i in range(1, n+1):
    if i >= k:
      break
    r = i
    d = 1
    while r < k:
      d = d * 2
      r = i * d
    s = s + 1 / (n * d)

print(s)

Submission status: Wrong Answer

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