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:
import math
N,K = map(int,input().split(" "))
LOOPER = math.ceil(math.log2(K))
P = 0
for i in range(N):
    DI = i+1
    SCORE = 0
    if LOOPER == 1:
        P += float((N-DI)/N)
        #print(float((N-DI)/N))
        break
    else:
        P += float(1/N) * float(1/2**LOOPER)
        LOOPER -= 1
    #print(P)
print(P)

Submission status: Wrong Answer

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


print(ans)

Submission status: Wrong Answer

Solution code:
import math


n, k = map(int, input().split())
if k == 1:
    print(1)
else:
    a = 1
    b = 0
    for i in range(1, n+1):
        if i >= k:
            a += (n-k+1)*(2**b)
            break
        else:
            if i == 1:
                b = math.ceil(math.log(k, 2))
            else:
                tmp = math.ceil(math.log(k, i) - 1.0)
                a += 2 ** (b - tmp)
    c = (2**b)*n
    print(a/c)

Submission status: Wrong Answer

Solution code:
import numpy as np
from decimal import Decimal

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

sum=0

for i in range(1,n+1):
    if i>=k:
        sum+=1
    else:
        sum+=1/(2**(int(np.log2(k/(i-0.1)))+1))

#print(Decimal(sum/n))
print('%.9f' % (sum/n))
#print("{:.9g}".format(sum/n))

Submission status: Wrong Answer

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

for n in range(1,N+1):
    if n >= K:
        prob += 1/N
    else:
        x = int(math.log(abs((K-n)/n))/math.log(2)) + 1
        prob += 1/(N*2**x)
print(prob)

Submission status: Wrong Answer

Solution code:
import sys
import math
from decimal import Decimal
input = sys.stdin.readline

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

power_list =[] 
K_flag = N
K_temp = K

if N > K:
    power_list.append(N-K+1)
    K_flag = K-1
else:
    power_list.append(0)

while K_temp > 1:
    power_list.append(0)
    K_temp /= 2
    if K_temp < K_flag:
        power_list[-1] += K_flag - math.floor(K_temp)
        K_flag = math.floor(K_temp)
    elif K_temp == K_flag:
        power_list[-1] += 1
        K_flag = math.floor(K_temp)

percentage_sum = Decimal("0.0")

for i in range(len(power_list)):
    dec_temp = math.pow(1.0/2,i)
    dec_temp = Decimal(str(dec_temp)) / Decimal(str(N))
    percentage_sum += power_list[i] * dec_temp

print(percentage_sum)

Submission status: Wrong Answer

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

# 1/nは最後に全部にかける
if k>=n:
    prob = Decimal('0')
else:
    prob = Decimal(str((n-k+1)*2))

list_prob = []
if k>n:
    for i in range(1,n+1):
        list_prob.append(int(Decimal(math.log2(Decimal(k))) - Decimal(math.log2(Decimal(i))))+1)

    for num in list_prob:
        prob = prob + Decimal('0.5')**Decimal(str(num-1))
else:
    for i in range(1,k):
        list_prob.append(int(math.log2(k/i))+1)
    for num in list_prob:
        prob = prob + Decimal('0.5')**Decimal(str(num-1))

prob = prob / Decimal(str(n)) / Decimal('2')
print(prob)

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(1,n+1):
  if i<k:
    ans += 0.5**int(math.log(k/i, 2)+1)
  else:
    ans += 1
    
print(ans/n)

Submission status: Wrong Answer

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

l_2 = []
x = 1
while 1:
    l_2.append(2 ** x)
    if 2 ** x > K:
        break
    x += 1

ans = 0
for i in range(N):
    if i + 1 >= K:
        ans += 1 / N
        continue
    for idx, val in enumerate(l_2):
        if (i + 1) * val > K:
            ans += 1 / N * 0.5 ** (idx + 1)
            break

print("%.20f" % ans)

Submission status: Wrong Answer

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

flag=0
total=float(0.0)
for x in range(N):
    #print(x)
    if x>K:
        #n=0
        flag=1
        break
    else:
        n=int(math.log2(K/(x+1)))+1.0
    #print(n)
    total+=(0.5**n)
    #print(total)
if flag==1:
    total+=(N-K)
total=float(total/N)
print(total)

Submission status: Wrong Answer

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

# 初期のサイコロであがる確率
dice = 0
if K <= N:
    dice = (N - K + 1) / N

# コイン
dice_st = min(N, K - 1)

patt = N
coin = 0

for r in range(1, dice_st+1):
    ren = int(math.log(K, 2) - math.log(r, 2)) + 1
#    print(ren, 2**ren, patt)
    coin += (1 / (2**ren))*(1/patt)

#print(dice, coin, dice + coin)
print(dice + coin)

Submission status: Wrong Answer

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

n, k = map(int, input().split())
array = []
two = [pow(2, i) for i in range(200)]
#print(two)
k_tikai = 0
for j in range(len(two)):
    if k > two[j]: k_tikai = j
k_tikai += 1
tasu = 0.0

for i in range(1, n+1):
    if i >= k:
        array.append(float(1)/n)
#        tasu += float(1)/n
        continue
    tikai = 0
    if i in two:
        tikai = two.index(i)
    else:
        for j in range(len(two)):
            if i > two[j]: tikai = j
        tikai += 1
#    print('i:{}'.format(i))
#    print('tikai:{} value:{}'.format(tikai, two[tikai]))

    time = k_tikai-tikai
#    print(time)
    if time>0:
        array.append((float(1)/n)*pow(1/2, time))
#        tasu += ((float(1)/n)*pow(1/2, time))
    else:
        array.append(float(1)/n)
#        tasu += (float(1)/n)


#print(k_tikai)
#print(two[k_tikai])

print(sum(array))

#print(tasu)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

c_2times = []
for i in range(N):
    c_2times.append(0)

prob_list = []
for d in range(1, N+1):
    point = d
    while True:
        if (point > K):    #(1 <= point <= K-1)
            break
        point *= 2
        c_2times[d-1] += 1
    prob_list.append(1/N * (1/2)**c_2times[d-1])

prob_sum = 0
for i in range(len(prob_list)):
    #print(prob_list[i])
    prob_sum += prob_list[i]

print(prob_sum)

Submission status: Wrong Answer

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

r = 0
def func(n):
	c, t = 0, n
	while t <= K:
		t <<= 1
		c += 1
	return c

base = func(1)
p = 2 ** (base - 1)
print((p - 1) / p / (2 * N))

Submission status: Wrong Answer

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

results = []
for i in range(1, n+1):
    if i >= k/2:
        results.extend([0.5 for _ in range(i,k)])
        results.extend([1 for _ in range(k,n+1)])
        break
    for j in range(1,k):
        if i * 2**j > k:
            break
    results.append((0.5)**j)
print(sum(results)/n)

Submission status: Wrong Answer

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

flag=0
total=float(0.0)
for x in range(N):
    print(x)
    if x>K:
        #n=0
        flag=1
        break
    else:
        n=int(math.log2(K/(x+1)))+1.0
    print(n)
    total+=(0.5**n)
    print(total)
if flag==1:
    total+=(N-K)
total=float(total/N)
print(total)

Submission status: Wrong Answer

Solution code:
# cook your dish here
import math
def power(x, y): 
  
    if(y == 0): return 1
    temp = power(x, int(y / 2))  
      
    if (y % 2 == 0): 
        return temp * temp 
    else: 
        if(y > 0): return x * temp * temp 
        else: return (temp * temp) / x 
        
n,k=map(int,input().split())
summ=0
for i in range(1,n+1):
    value=0
    if i<k:
        y=k/i
        value=math.log(y,2)
        value=int(value)
        value+=1
    po=power(0.5,value)
    summ+=po
    
summ=summ/n
print('{0:.12f}'.format(summ))

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
from fractions import Fraction
 
n, k = [int(elem) for elem in input().split()]
prob = 0
 
for i in range(1, n+1):
    tmp = math.log2(Fraction(k,i))
    if tmp <= 0:
        num = 0
        prob += Fraction(1,n)
    else:
        num = int(tmp) + 1
        prob += Fraction(1,n) * (Fraction(1,2) ** num)

a = np.array(prob.numerator, dtype=np.int)
b = np.array(prob.denominator, dtype=np.int)
print(a/b)

Submission status: Wrong Answer

Solution code:
import math
a,b=input().split()
P=[]
for x in range(int(a)):
    v=math.log2(int(b)/(x+1))
    if int(v)<1:
        y=0
    else:
        y=int(v)+1
    
        
    P.append(1/int(a)*pow(2,-y))



print(sum(P))

Submission status: Wrong Answer

Solution code:
from decimal import *

import math

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

# 計算しない範囲を求める
# 100 10 なら 100-10 + 1/100はかつ

getcontext().prec = 100
result =Decimal(0)
if N > K:
    #print(Decimal((N-K)/N))
    #result = Decimal((N-K+1)/N)
    result = Decimal((N-K)/N)

for i in range(1,min(N,K) + 1):
    #print(i)
    #print(1/2 ** i)
    #print(Decimal((1 / N ) * ((1/2) ** (i+1) )))
    #result += Decimal((1 / N ) * ((1/2) ** (i+1) ))
    #result += Decimal(1 / (N * (2 ** (i))))
    #print(N * (2 ** i))
    beki = 0
    if i == 1:
        if N == K:
            beki = int(math.log(K,i * 2))
        else:
            beki = int(math.log(K,i * 2)) + 1
        #print('a' , math.log(K,i * 2))
        #print('a' , beki)
    elif  math.log(K,i) > 1:
        beki = int(math.log(K,i))
        #print('b',beki)

    #print(int(math.log(K,i * 2)))
    result += Decimal((1 / (N * (2 ** beki))))
    #print (Decimal((1 / (N * (2 ** beki)))))
    #print(Decimal(1 / (N * (2 ** (i)))))
print(result)



#print(''.join(S))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = 0
for i in range(1,n+1):
    if 2*i <= k:
        a += 1
b = 0
c = 0
if n >= k:
    for i in range(a,0,-1):
        b += (1/n)*(1/2)**(i+1)
        c = (n-k+2)/n
else:
    for i in range(a,0,-1):
        b += (1/n)*(1/2)**(i+1)
print(b+c)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
i=0
p=0
u=0
sum_a=0
number=[]
if N>=K:
    num = K
else:
    num = N
for a in range(1,num+1):
    sum_a=a
    while u<=1:
        sum_a1=sum_a*2
        sum_a =+sum_a1
        #print(sum_a)
        i=i+1
        #print(sum_a)
        if (sum_a)>=K:
            u=2
    number.append(i)
    u=0
    i=0
    sum_a1=0
if num!=N:
    for i in range(N-K):
        number.append(0)
for i in range(N):
    if number[i]!=0:
        a=(1/2)**int(number[i])
        #print(a)
        p = p +((1/N)*a)
        #print(p)
    else:
        p=p + (1/N)
    

print(p)

Submission status: Wrong Answer

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

c_2times = []
for i in range(N):
    c_2times.append(0)

prob_list = []
for d in range(1, N+1):
    point = d
    while True:
        if (point > K):    #(1 <= point <= K-1)
            break
        point *= 2
        c_2times[d-1] += 1
    prob_list.append(1/N * (1/2)**c_2times[d-1])

prob_sum = 0
for i in range(len(prob_list)):
    #print(prob_list[i])
    prob_sum += prob_list[i]

print(prob_sum/100)

Submission status: Wrong Answer

Solution code:
import math

log = math.log(8, 2)

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

sum = 0

for i in range(1, n+1):
    exp  = math.log(k/i, 0.5)
    current = 1/n * 0.5**(1 + math.floor(abs(exp)))
    if exp >= 0:
        exp = 0
        current = 1/n 
    sum += current

if k == 1:
    print(1)
else:
    print(sum)

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.log2(K) - np.log2(n)
        return np.ceil(x_raw)

def get_prob_inv(n, K):
    x = get_x(n, K)
    if x == 0:
        return 1
    else:
        return (1/2)**x
    
x_alls = [get_x(n, K) for n in range(1, N+1)]
x_max = np.max(x_alls)
x_sum = np.sum(x_alls)
x_minus_x_max = x_sum - x_max
x_denos = [x_sum - x - x_minus_x_max for x in x_alls]
x_nume = x_max

ans = np.sum([2 ** x for x in x_denos])
ans = np.divide(ans, 2**x_max * N, dtype=np.float64)


# ans = np.sum([get_prob(n, K) for n in range(1, N+1)], dtype=np.float64)

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

Submission status: Wrong Answer

Solution code:
N, K = [int(s) for s in input().split()]
c0 = float(max(N-K+1, 0))/float(N)
c1 = 0
Kto = K-1
Kt = (K-1)//2
n = 1
flg = False
while True:
  if int(Kto)&2 == 1:
    c1 += (Kto-Kt+1)*pow(0.5, n)/float(N)
  else:
    c1 += (Kto-Kt)*pow(0.5, n)/float(N)
  Kto = Kt*1.0
  Kt = Kt//2
  n += 1
  if flg:
    break
  if Kt == 0:
    flg = True

print('{0:.11f}'.format(c0+c1))

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
ans=max(0.0,N+1-K)
r=K-1
p=1.0
i=1
import math
while r>0:
    l=min(r,math.ceil(K/(i*2)))
    p/=2
    if r<N:
        ans+=p*(r+1-l)
    elif l<=N:
        ans+=p*(N+1-l)
    r=l-1
    i+=1
print(ans/N)

Submission status: Wrong Answer

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

for i in range(N):
    n = i + 1
    Sum += pow(0.5, math.ceil(math.log(K/n, 2))) / N
print(Sum)

Submission status: Wrong Answer

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

p = 0.0
M = N
if N >= K:
	p += (N-K+1)
	M = K-1

t = 1
for i in range(0,30):
	if M*t >= K:
		break
	t *= 2

q = 0.0
while(M > 0):
	L = -(-M // t)
	q += L/t
	M = M-L
	t *= 2
p += q
print(p/N)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
N, K = map(int, input().split())
ans = 0
for i in range(N):
  if i+1 >= K:
    ans += 1/N
  else:
    ans += 1/N*pow(0.5, len(bin(math.floor(K/(i+1))))-2)

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:
            n = 0
            p = 1/N
        else:
            n = math.floor(math.log2(K/i - 1)) + 1
            p = math.pow(1/2, n)/N
        probabilitys.append(p)
    result = sum(probabilitys)
    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
n,k=list(map(int,input().split()))
a=0
for i in range(1,n+1):
  ex=math.ceil(math.log2(k/i))
  a+=(1/2)**(ex)
  if n>=k:
    break
print(a/n)

Submission status: Wrong Answer

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

ls = []

def multiply(ls):
    result = []
    for i in range(len(ls)):
        result.append(pow(N, -1) * ls[i])
    return result

def sq(n):
    return pow(n, -cnt)

if N < K:
    for i in range(1, N + 1):
        p = i
        cnt = 0
        while p < K:
            p *= 2
            cnt += 1
        ls.append(pow(2, -cnt))
    print(sum(multiply(ls)))
else:
    for i in range(1, K):
        p = i
        cnt = 0
        while p < K:
            p *= 2
            cnt += 1
        ls.append(pow(2, -cnt))
    print(sum(multiply(ls)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Wr=0
if N>=K:
    Wr = Wr+ (N-K+1)/N
    count = 1
    tmp = K
    while count<35 and tmp>=1.0:
        tmp = tmp / 2.0
        if N>tmp:
            dice = min(int(N -tmp) + 1, int(tmp*2)-int(tmp) )
            Wr = Wr+ dice/N/(2**count)
        count = count + 1
else:
    count = 1
    tmp = K
    while count<35 and tmp>=1.0:
        tmp = tmp / 2.0
        if N>tmp:
            dice = min(int(N -tmp) + 1, int(tmp*2)-int(tmp) )
            Wr = Wr+ dice/N/(2**count)
        count = count + 1
print(Wr)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
from decimal import *
N,K = map(int,input().split())
list = []
for i in range(1,N+1):
    if i >= K:
        list.append(float(Fraction(N-i+1,N)))
        break
    n = i
    count = 0
    while n <= K:
        n *= 2
        count += 1
    list.append(float(Fraction(1,N)*(Fraction(1,2)**count)))

print(Decimal(sum(list)))

Submission status: Wrong Answer

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

# 1/nは最後に全部にかける
if k>=n:
    prob = Decimal('0')
else:
    prob = Decimal(str((n-k+1)*2))

list_prob = []
if k>=n:
    for i in range(1,n+1):
        list_prob.append(int(Decimal(math.log2(Decimal(k))) - Decimal(math.log2(Decimal(i))))+1)

    for num in list_prob:
        prob = prob + Decimal('0.5')**Decimal(str(num-1))
else:
    for i in range(1,k):
        list_prob.append(int(math.log2(k/i))+1)
    for num in list_prob:
        prob = prob + Decimal('0.5')**Decimal(str(num-1))

prob = prob / Decimal(str(n)) / Decimal('2')
print(prob)

Submission status: Wrong Answer

Solution code:
import math

N, K = map(int, input().split())
N_1 = N
p, ans = 1, 0
while True:
  if N > K / p:
    B = math.ceil(K / p)
    s = N - B + 1
    ans += s / p
    N -= s
  if N == 0:
    break
  p *= 2
print(format(ans/N_1, '.10f'))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = 0
for i in range(1,n+1):
    if 2*i <= k:
        a += 1
b = 0
c = 0
if n > k:
    for i in range(a,0,-1):
        b += (1/n)*(1/2)**(i+1)
        c = (n-k+2)/n
else:
    for i in range(a,0,-1):
        b += (1/n)*(1/2)**(i+1)
print(b+c)

Submission status: Wrong Answer

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

b=1
S=0
a=0
m=0
for i in range(1,n+1):
    a=k//i
    b=1
    for j in range(0,100000):
        b=b*2
        if b>a:
            m=j
            break
        else:
            continue
    

    S=S+(1/(n*2**(m+1)))

print(S)

Submission status: Wrong Answer

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

import math
total=0

def log(a,b):
  c=b/a
  ans=math.ceil(math.log2(c))
  return ans

for i in range(1,N+1):
    ratio= 2**log(i,K)
    prob=1/ratio
    total+=prob
    print(i,prob,total)
    
print(total/N)

Submission status: Wrong Answer

Solution code:
# from fractions import Fraction
from decimal import Decimal
li = input().split()
n = int(li[0])
k = int(li[1])

# n面サイコロ kは得点

# 1/nの確率で1~nが出る
# 勝つためにx回表を出し続ければ良い
# 目 * 2^x >= kとなればよい

answer = 0
for i in range(n):
    dicenum = i + 1
    winline = dicenum
    x = 0
    while winline < k:
        x += 1
        winline = dicenum * (2**x)
    if dicenum == 1:
        first_x = x
        bunbo = n * 2**x
        bunsi = 1
    elif x == 0:
        bunsi += 2**first_x
    else:
        if first_x == x:
            bunsi += 1
        else:
            bunsi += (first_x - x) * 2

answer = Decimal(str(bunsi)) / Decimal(str(bunbo))
# answer = float(Fraction(bunsi, bunbo))
# answer = float(bunsi) / bunbo
print("{:.12f}".format(answer))

Submission status: Wrong Answer

Solution code:
from decimal import *

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 += (1/n) * (1/get_fact(count))

print(r)

Submission status: Wrong Answer

Solution code:
import math

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

probability = 0

lastend = N + 1
for i in range(math.ceil(math.sqrt(K))+1):
    if N < K and i < round(math.sqrt(K/N)):
        continue
    core = lastend - math.ceil(K/(2**i))
    lastend = math.ceil(K/(2**i))
    #print(i,core,lastend)
    probability += (core/N)*((1/2)**i)

print(probability)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = 0
for i in range(1,n+1):
    if 2*i <= k:
        a += 1
b = 0
c = 0
if n > k:
    for i in range(a,0,-1):
        b += (1/n)*(1/2)**(i+1)
        c = (n-k+1)/n
else:
    for i in range(a,0,-1):
        b += (1/n)*(1/2)**(i+1)
print(b+c)

Submission status: Wrong Answer

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

prob_cl = 0
if N > K:
    prob_cl = (N - K) / N

prob = 0
K_n = K
for i in range(1, N+1):
    count = 0
    while True:
        i *= 2
        count += 1
        if i >= K:
            prob += (1/2)**count / N
            break
                
print(prob_cl + prob * (1 - prob_cl))

Submission status: Wrong Answer

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

b=1
S=0
a=0
m=0
for i in range(1,n+1):
    a=k//i
    b=1
    for j in range(0,100000):
        b=b*2
        if b>a:
            m=j
            break
        else:
            continue
    print(1/(n*2**(m+1)))

    S=S+(1/(n*2**(m+1)))

print(S)

Submission status: Wrong Answer

Solution code:
from decimal import *

import math

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

# 計算しない範囲を求める
# 100 10 なら 100-10 + 1/100はかつ

result =Decimal(0)
if N > K:
    #print(Decimal((N-K)/N))
    #result = Decimal((N-K+1)/N)
    result = Decimal((N-K)/N)

for i in range(1,min(N,K) + 1):
    #print(i)
    #print(1/2 ** i)
    #print(Decimal((1 / N ) * ((1/2) ** (i+1) )))
    #result += Decimal((1 / N ) * ((1/2) ** (i+1) ))
    #result += Decimal(1 / (N * (2 ** (i))))
    #print(N * (2 ** i))
    beki = 0
    if i == 1:
        if N == K:
            beki = int(math.log(K,i * 2))
        else:
            beki = int(math.log(K,i * 2)) + 1
        #print('a' , math.log(K,i * 2))
        #print('a' , beki)
    elif  math.log(K,i) > 1:
        beki = int(math.log(K,i))
        #print('b',beki)

    #print(int(math.log(K,i * 2)))
    result += Decimal((1 / (N * (2 ** beki))))
    #print (Decimal((1 / (N * (2 ** beki)))))
    #print(Decimal(1 / (N * (2 ** (i)))))
print(result)



#print(''.join(S))

Submission status: Wrong Answer

Solution code:
import math
n, k = map(int, input().split(' '))
if n >= k:
  prob = 1 - (k - 1) / n
else:
  prob = 0

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

Submission status: Wrong Answer

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

P = 0
for i in range(1,N):
  if i>= K:
    P += 1
  else:
    S = K - i
    j = 1
    P2 = 1
    while ( i*(2**j) >= S):
      j += 1
      P2 *= 2
    P += (1/N)*(1/P2)
  

print(P)

Submission status: Wrong Answer

Solution code:
from math import log,ceil
def solve():
    N,K = map(int, input().split())
    if N == 1 and K != 1:
        print("0")
        exit()
        
    elif N == 1 and K ==  1:
        print("1")
        exit(0)

    
    ans = 0
    for x in range(1, N+1): # xは初期値
        kaisuu = ceil( log( K / x, 2))
        # tmp = pow(0.5, kaisuu)
        tmp = 1/N
        for i in range(kaisuu):
            tmp *= 0.5
        ans += tmp 
    # ans /= N
    print(ans)
        

    
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

for i in range(1,N+1):
	for j in range(1,10000000):
		if(i*(2**j) >= K):
			break

	prob=(1/N) * ((1/2)**(j))
	prob_sum+=prob
print(prob_sum)

Submission status: Wrong Answer

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

#n = 3
#k = 10
p = 0
for i in range(1, n + 1):

    num = 0
    while i <= k:
        i *= 2
        num += 1
    p += (0.5 ** num) / n
print(p)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
def main():
  input = sys.stdin.readline
  N, K =map(int,input().split())
  p = []
  for d in range(1,N+1):
    if d >= K:
      p.append(1/N)
    else:
      n = math.ceil(np.log2((K-1)/d)) 
      p.append( 1/N * 1/2 ** n)
  print(sum(p))
main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n, k = map(int, input().split())
r = 0
for i in range(1, n + 1):
    if i >= k:
        print((r + (n - k + 1))/ n)
        break
    t = np.log2(10 / i)
    if t.is_integer():
        r += (1 / 2) ** int(t)
    else:
        r += (1 / 2) ** (int(t) + 1)
else:
    print(r / n)

Submission status: Wrong Answer

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


if K==1:
    print(1)
    exit(0)
ans=0
if N>=K:
    SA=N-K
    NN=N
    N=K-1
    point=K//2

    if point >N:
        point=N

    ans+=0.5*(N-point)
    n=point
    count=K//(2.0*n)+1
    ans+=(0.5)**count
    harf=(0.5)**count


    for i in range (n-1):
        harf=0.5*harf
        ans+=harf
    print(((SA+1)+ans)/NN)
    exit(0)
else:

    point=K//2

    if point >N:
        point=N

    ans+=0.5*(N-point)
    n=point
    count=K//(2*n)+1
    ans+=(0.5)**count
    harf=(0.5)**count

    for i in range (n-1):
        harf=0.5*harf
        ans+=harf
    print(ans/N)

Submission status: Wrong Answer

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

if N >= K:
    ans2 = (1/N) * (N - K+1)
    now = 1
    count = 0
    while True:
        if now >= K:
            break
        now *= 2
        count += 1

    ans = (1/N) * ((0.5) ** (count))

    A = [ans]

    for i in range(1,K):
        A.append(A[i-1]*2)
    print(sum(A)+ans2)
else:
    now = N
    count = 0
    while True:
        if now >= K:
            break
        now *= 2
        count += 1

    ans = (1/N) * ((0.5) ** count)

    A = [ans]

    for i in range(1,N):
        A.append(A[i-1]*0.5)

    print(sum(A))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = 0
for i in range(1,n+1):
    if 2*i <= k:
        a += 1
b = 0
c = 0
if n > k:
    for i in range(a,0,-1):
        b += (1/n)*(1/2)**(i+1)
        c = (n-k)/n
else:
    for i in range(a,0,-1):
        b += (1/n)*(1/2)**(i+1)
print(b+c)

Submission status: Wrong Answer

Solution code:
import math

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

minNK = min(N, K-1)
#print(N, K-1, minNK)

sumA = 0

for i in range(1, minNK+1):
    c, k = 0, K
    while k >= i:
        k = int(k / 2)
        c += 1
    #print(i, c)
    sumA += (1.0 / float(N)) * math.pow(0.5, c)
#print(sumA)

if N >= K:
    sumA += (float(N - K + 1) / float(N))
print(sumA)

Submission status: Wrong Answer

Solution code:
import sys
import math
 
a,b=map(int, input().split())
 
probablity = 0.0
 
for i in range(a + 1):
  ceil = math.ceil(math.log2(b / (i + 1)))
  if(ceil < 0):
    ceil = 0
  elif(ceil < 1):
    ceil = 1
    
  probablity = probablity + 1 / (a * 2 ** ceil)
  
print(probablity)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# 1/nは最後に全部にかける
if k>=n:
    prob = Decimal('0')
else:
    prob = Decimal(str((n-k+1)*2))

list_prob = []
if k>=n:
    for i in range(1,n+1):
        list_prob.append(int(math.log2(k/i))+1)

    for num in list_prob:
        prob = prob + Decimal('0.5')**Decimal(str(num-1))
else:
    for i in range(1,k):
        list_prob.append(int(math.log2(k/i))+1)
    for num in list_prob:
        prob = prob + Decimal('0.5')**Decimal(str(num-1))

prob = prob / Decimal(str(n)) / Decimal('2')
print(prob)

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

Solution code:
import math

log = math.log(8, 2)

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

sum = 0

for i in range(1, n+1):
    exp  = math.log(k/i, 0.5)
    current = 1/n * 0.5**(1 + math.floor(abs(exp)))
    if exp >= 0:
        exp = 0
        current = 1/n 
    sum += current


print(sum)

Submission status: Wrong Answer

Solution code:

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

    ans = 0.0
    for n in range(1, N+1):
        num = n
        i = 0

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

        ans += float((1/N)*((1/2)**i))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import math

n, k = [int(x) for x in input().rstrip().split(" ")]
proba = 1 / n
proba_coin_fractions = []
for i in range(1, n + 1):
    if i >= k:
        proba_coin_fractions.append(1.0)
        continue
    min_power_over_k = int(1 + math.log(k / i, 2))
    if min_power_over_k < 1:
        min_power_over_k = 0
    proba_coin_fractions.append(1.0 / int(2 ** min_power_over_k))

proba *= sum(proba_coin_fractions)
print("%1.20f" % float(proba))

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
from decimal import *
N,K = map(int,input().split())
list = []
for i in range(1,N+1):
    if i >= K:
        list.append(Fraction(1,N))
        continue
    n = i
    count = 0
    while n <= K:
        n *= 2
        count += 1
    list.append(Fraction(1,N)*(Fraction(1,2)**count))

print(float(sum(list)))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import math

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

l = []
ln = n+1/2**k
l.append(math.ceil(ln-k) if ln-k>=0 else 0)
ln -= math.ceil(ln-k) if ln-k>=0 else 0

for _ in range(1,k):
    k/=2
    l.append(math.ceil(ln-k) if n-k>0 else 0)
    ln-=math.ceil(ln-k) if n-k>0 else 0
    if k<=1:
        break

ans = 0
for i in range(len(l)):
    ans += l[i]/n/2**i
print(ans)

Submission status: Wrong Answer

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