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:
def li():
    return list(map(int, input().split()))


if __name__ == '__main__':
    [n, k] = li()

    # 最初の目がk以上で勝つ確率
    win1 = max(0, (n - k + 1))
    # print(win1)

    # コインを投げる最大回数
    coin_max_num = len(bin(k)) - 2
    win_list = []
    candidate_list = []

    for coin in range(1, coin_max_num + 1):
        upper = min(n, (k + 2 ** coin - 1) // 2 ** coin)
        # print(upper)
        candidate = max(upper + 1 - (k + 2 ** coin - 1) // 2 ** coin, 0)
        candidate_list.append(candidate)
        # print(candidate)
        # print()

        win_list.append(max(0, candidate * 0.5 ** coin * candidate * 10 ** 7))
    # print(win_list)
    print((win1 * 10 ** 7 + sum(win_list)) / (n * 10 ** 7))

    # upper = min(n, k)
    # win_list.append(max(0, (upper - (k + 2**1-1) // 2) / n) * 0.5 ** 1)

    # upper = min(n, (k + 1) // 2)
    # win_list.append(max(0, (upper - (k+2**2-1) // 2**2) / n) * 0.5 ** 2)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
ans=0
con=0
m=n
l=k-1
INF=10**5

for i in range(INF):
    if m>l:
        p=(m-l)/n*((1/2)**i)
        m=l
        ans+=p
    if l==0:
        break
    if l%2==0:
        l=k//(2**(i+1))
    else:
        l=k//(2**(i+1))
    
        
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import math
N ,K=map(int ,raw_input().split())

C = []
for i in range(N):
    C.append(int(math.ceil(np.log2(K)-np.log2(i+1))))
P = 0.000
C.sort()
k =C[0]
t = 0
p = 0.5**(k-1)
l = 0
#print(C)
for n in C:
    if k != n:
        p=p*t/(2**(n-k))
        P+=p
        l = k
        k=n
        #print p*t,n,p,t
        t = 1
    else:
        t +=1
#print p
#print C[len(C)-1]-k
p=p*t/(2**(k-l))
#p = p/2
P+=p
#print p*t,n,p,t
#print P
print (P/N)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
if  N >= K:
    ans+= (N-K+1)/N
    max_N = K
else:
    max_N = N

for x in range(max_N):
    ans+=pow(1/2,int(np.log2(K/(x+1)))+1)/N

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
 
n, k = map(int, input().split())
ans = 0
 
for i in range(1, n + 1):
  if i >= k:
    ans += 1.0 / n
    
  ans += np.power(1 / 2, np.ceil(np.log2(k / i))) / n
  
print(ans)

Submission status: Wrong Answer

Solution code:
from decimal import *

N, K = map(int, input().split())
getcontext().prec = 10
point = 0
percent = Decimal(0)
for n in range(N):
    point = n + 1
    per = Decimal(1)/Decimal(N)
    while point < K:
        point *= 2
        per *= Decimal(0.5)
    percent += Decimal(per)
    point = 0

print(percent)

Submission status: Wrong Answer

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

import math
val = K
curr_max = N
result = 0

pow_count = 0
while curr_max >= 1:
    if curr_max >= val:
        result += math.ceil(curr_max-val)/N * (0.5) ** pow_count
        curr_max = int(val)
    val *= 0.5
    pow_count += 1

print result

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import numpy as np


def solv(n, k):
    d = np.arange(1, n+1, dtype='float64')
    print(d)
    p = np.fmax(k / d, 1)
    print(p)
    t = np.ceil(np.log2(p))
    r = np.power(0.5, t)
    return np.mean(r)


if __name__ == '__main__':

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

    print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
i = 0
while(True):
    if((k-1)//pow(2,i)==0):
        break
    i+=1
s = 0
for l in range(min(n,k)):
    s+=((1/n)*(0.5**i))
    i-=1
    if(i==0):
        i=1
if(n>=k):
    print(1-s)
else:
    print(s)

Submission status: Wrong Answer

Solution code:

N, K = input().split()

p = 0

for i in range(1,int(N)+1):
    score = i
    j = 0
    while True:
        score = score*2
        j += 1
        if score >= int(K):
            break
    p1 = 1/int(N)
    p2 = (1/2)**int(j)
    p += p1 * p2

print(p)

Submission status: Wrong Answer

Solution code:
import math

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

ans = 0
for i in range(1, n+1):
    dice = int(math.log2(k / i) + 1)
    if i >= k:
        ans += 1 / n
        continue
    ans += 1 / (n * 2**dice)
print(ans)

Submission status: Wrong Answer

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

L = math.ceil(math.log(K,2))
#print(L)

S = 0.0
if N >= K:
	S += (N-K)/N
for i in range(L):
	T = math.ceil(K/2**i)
	B = math.ceil(K/2**(i+1))
#	print(i,T,B,(T-B)/2**(i+1))
	if N >= T:
		S += (1/N)*(T-B)/2.0**(i+1)
#		print("N>T",(1/N)*(T-B)/2.0**(i+1))
	elif T > N >=B:
		S += (1/N)*(N+1-B)/2.0**(i+1)
#		print("T>N>=B",(1/N)*(N+1-B)/2.0**(i+1))
	elif N==B:
		S += (1/N)*(N+1-B)/2.0**(i+1)
#		print("T>N>=B",(1/N)*(N+1-B)/2.0**(i+1))
print(S)

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 < 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:
import math
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()

n, k = MI()
ans = 0
ans2 = 0
for i in range(1, n+1):
    if i == k:
        break
    print(k/i)
    print(math.floor(math.log(k/i,2)))
    ans += ((1/n) * (0.5 ** math.ceil(math.log(k/i, 2))))
if n - k > 0:
    # ans += ((1/n) * (n-k))
    ans2 += ((1/n) * (n-k))
print(ans+ans2)

Submission status: Wrong Answer

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

def get_n(num, K):
    score = num
    for i in range(1, 20):
       score = score * 2
       if score > K:
           return i
    return None

for i in range(1, N+1):
    n = get_n(i, K)
    i_score = (1/N) * ((1/2)**n)
    result += i_score

print(result)

Submission status: Wrong Answer

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

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

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

print(S)

Submission status: Wrong Answer

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


def Cal(N, K):
    if N <= K:
        pro = Decimal(0)
        for n in range(1, N+1):
            for j in range(0, K):
                n = n * 2
                if n >= K:
                    break
            pro += (Decimal(1) / Decimal(N * 2**(j+1)))
        return pro
    else:
        pro = Decimal(N-K+1) / Decimal(N)
        for n in range(1, K):
            for j in range(0, K):
                n = n * 2
                if n >= K:
                    break
            pro += (Decimal(1) / Decimal(N * 2**(j+1)))
        return pro


ans = Cal(N, K)
print(ans)

Submission status: Wrong Answer

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

if(n>k):
    man = 1.0
else:
    man = 0
mod = n
qtdMin = 1/n
mid = 1
qtd = 0
while(mod<k):
    mod<<=1
    qtdMin*=0.5
    mid<<=1
    qtd+=1

mod = qtdMin
for i in range(min(n,k)-1,0,-1):
    if(i*mid < k):
        qtd+=1
        mod*=0.5
        mid<<=1
        
    qtdMin += mod
print(abs(man-qtdMin))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import os

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

count=[0]*N

print(count)
KK=K
i=0
while  KK >= 1:
    i=i+1
    for j in range(KK):
        if j<N:
            count[j]=count[j]+1
        #print(j)
        #print(count)
    KK=int(KK/2)

sum=0
for l in range(N):
    sum=sum + (1/N)*(1/2)**(count[l])
    
print(sum)

Submission status: Wrong Answer

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

poss = 0
for i in range(1,N):
	point = i
	cou = 0
	while point <= K-1:
		point *= 2
		cou=cou+1
	poss = poss + 0.5 **(cou)
print(poss)

Submission status: Wrong Answer

Solution code:
from math import log

n,k = (int(num) for num in input().split())
p = 1/n
ans = 0.0

def isPower(n):
    if n == 2 or n==1:
        return True
    elif n%2 == 1 or abs(int(n)-n) > 0.00001:
        return False
    else:
        isPower(n//2)
    

if n >= k:
    ans += p * (n-k+1)
    for i in range(1,k):
        if isPower(k/i):
            ans += p*(1/2)**(int(log(k/i,2)))
        else:
            ans += p*(1/2)**(int(log(k/i,2))+1)
        
else:
    for i in range(1,n+1):
        if isPower(k/i):
            ans += p*(1/2)**(int(log(k/i,2)))
        else:
            ans += p*(1/2)**(int(log(k/i,2))+1)
        
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
lst=[]
a=1
cnt=0
for m in range(1,n+1):
  for i in range(100000):
    if m*a>=k:
      lst.append(cnt)
      break
    else:
      a*=2
      cnt+=1
totl=0
for j in range(n):
  totl+=0.5**lst[j]
print(totl/n)

Submission status: Wrong Answer

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

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

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

print(S)

Submission status: Wrong Answer

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

p = 1
while p < k:
    p = p << 1
pb = (p >> 1)-1
c = n - k + 1
if c <= 0:
    c = 0

print(pb)
print(p)
print(c)

print((pb + p * c) / p / n)

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split()]
sum = 0
float(sum)
for i in range(1, N + 1):
    b = i
    con = 0
    while K > b:
        b = b * 2
        con += 1
        print(con)
    else:
        sum += 1 / N * (0.5 ** con)

print(sum)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, K = read_int()

def solve():
    ans = 0.0
    # 2のべき乗のリスト
    l = []
    i = 1
    while i < K:
        l.append(i)
        i *= 2
    # print(l)

    over = 0
    for i in range(1, N + 1):
        b = K // i
        if i >= K:
            # ans += 1 / N
            over += 1
            continue
        p = bisect.bisect_right(l, b)
        # print(p)
        ans += 1 / (N * (2 ** p))
    ans += over / N

    return ans

if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
kaisu=[]
for i in range(1,n+1):
    if i >=k:
        kaisu.append(1)
    else:
        for j in range(100):
            if pow(2,j)>(k/i):
                kaisu.append(1/2**j)
                break
ans=sum(kaisu)/n
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
	N, K = map(int, input().split())
	dp = [0 for _ in range(K+1)]

	if K > N:
		for i in range(1, N+1):
			dp[i] = 1
	else:
		for i in range(1, K):
			dp[i] = 1
		dp[K] += (N-K+1)
	ans = dp[K]
	for i in range(1, min(N+1, K)):
		cur = i
		this_p = dp[i]
		rep = 1
		while cur <= K:
			rep *= 0.5
			cur *= 2
		ans += this_p*rep
	print(ans/N)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
ans = 0
for v in range(1, n+1):
    p = 1
    p *= 1/n
    while v <= k:
        v = v * 2
        p *= 1/2
    ans += p
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
num = 0
point = 0
cnt = 0
for i in range(1,N+1):
    if 1 <= i and i <= (K-1):
        point = i
        print(point)
        cnt = 0
        while 1:
            if point >= K:
                break
            else:
                point *= 2
                cnt += 1
        num += float((1/N) * ((1/2) ** cnt))
    elif i >= K:
        num += float((1/N))

print(num)

Submission status: Wrong Answer

Solution code:
import math

N,K = map(int,input().split())
result = 0
N1 = 1.0/N
LK = math.log(K)
for i in range(N):
    l = math.ceil(LK/math.log(2.0)) if i==0 else math.ceil(LK/math.log(i+1)) - 1.0
    result +=  N1/math.pow(2.0, l)

print(result)

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([(1/2) 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((1/2**j))
print(sum(results)/n)

Submission status: Wrong Answer

Solution code:
#C
import math
N, K = map(int, input().split())
p = [float(0)] * N
for d in range(1, N+1):
    if d >= K:
        p[d-1] = 1.0 / N
    else:
        c = int(math.log(K/d, 2)) + 1
        p[d-1] = (1/2) ** c / N
print(sum(p))

Submission status: Wrong Answer

Solution code:
from decimal import *
N,K = map(int, raw_input().split())
ans = Decimal(0)
if N > K:
	ans += Decimal(N-K+1)/Decimal(N)
pre = min(N+1,K)
sisu = 1
while True:
	if(pre == 1):
		break
	now = K - (K * (2**sisu - 1))/ (2**sisu)
	if(pre > now):
		ans += Decimal(pre-now)/Decimal(N * 2**sisu)
	sisu += 1
	pre = min(now,N+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N, K = map(int,input().split())
#N, K = 100000, 5

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

ans = (1/N) * total
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N, K = map(float, (map(int, input().split(" "))))
prob_win = 0
for i in reversed(range(1, int(N+1))):
    i = float(i)
    if i == 1:
        S = math.ceil(math.log(K) / math.log(2))
        prob_win += (1/N) * ((1/2) ** S)
        break
    elif i >= K:
        prob_win += (1 / N)
    else:
        S = math.ceil(math.log(K)/math.log(i) * math.log(2))
        prob_win += (1/N) * ((1/2) ** S)
print(prob_win)

Submission status: Wrong Answer

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

S=0

for i in range(1,N+1):
    S+=(1/N)*((1/2)**(int(math.log2(K/i)+1)))
print(S)

Submission status: Wrong Answer

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

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

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.log(k/i,2))
  a+=1/n*(1/2)**(ex)
print(a)

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(i + 1, k))
  prob = prob + 1 / n * (1 / 2**l)
  
print(prob)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int, input().split())
ans = 0
logK = np.log2(K)
if N < K:
    for i in range(N):
        sisu = int(logK - np.log2(i + 1))
        ans +=1 / (2 ** sisu)
    print(ans/(2 * N))
else:
    for i in range(K - 1):
        sisu = int(logK - np.log2(i + 1))
        ans +=1 / (2 ** sisu)
    ans = ans / (2 * N)    
    ans += 1 - (K - 1) / N
    print(ans)

Submission status: Wrong Answer

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

ans = 0

for i in range(1,n+1):
    #print(i)
    if i == k:
        ans += n-k+1
        break
    for j in range(1,200000):
        if i * (2**j) > k:
            ans += (1/2)**j
            #print(ans)
            break

ans = ans * 1.0/n

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import math
from fractions import Fraction

n, k = [int(x) for x in input().rstrip().split(" ")]
proba = Fraction(1, n)
proba_coin_fractions = []  # type: list[Fraction]
for i in range(1, n + 1):
    if i >= k:
        proba_coin_fractions.append(Fraction(1, 1))
        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(Fraction(1, int(2 ** min_power_over_k)))

proba *= sum(proba_coin_fractions)
print(float(proba))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import math
N ,K=map(int ,raw_input().split())

C = []
for i in range(N):
    C.append(int(math.ceil(np.log2(K)-np.log2(i+1))))
P = 0.000
C.sort()
k =C[0]
t = 0
p = 0.5**(k-1)
l = 0
#print(C)
for n in C:
    if k != n:
        p=p/(2**(n-k))
        P+=p*t
        l = k
        k=n
        #print p*t,n,p,t
        t = 1
    else:
        t +=1
#print p
#print C[len(C)-1]-k
p=p/(2**(k-l))
#p = p/2
P+=p*t
#print p*t,n,p,t
#print P
print (P/N)

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):
    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:
N,K = map(int, input().split())
l = []
for i in range(N):
    a = 0
    if i > K:
        break
    for j in range(K):
        if j == 0:
            a = i+1
        else:
            a = a * 2
        if a >= K:
            break
    kakuritsu = 1/N*0.5**j
    l.append(kakuritsu)
print(sum(l))

Submission status: Wrong Answer

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

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

    while(i * 2**cnt)  < 10:
        cnt += 1

    ans += (1.0 / 2**cnt)

ans = ans / n

print(ans)

Submission status: Wrong Answer

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

# In[8]:


import math


# In[43]:


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


# In[66]:


ans = 0
for i in range(1,N+1):
    ans += (1/2)**(max(math.floor(math.log(K/i, 2)) + 1, 0))/N


# In[67]:


print(ans)


# In[ ]:

Submission status: Wrong Answer

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


sum=0

for i in range(1,N+1):
  if i>=K:
    sum=sum+(1/N)
  else:
    sum=sum+(1/N)*((1/2)**(int(math.log2(K/i))+1))
print(sum)

Submission status: Wrong Answer

Solution code:
from decimal import *
N,K = map(int, raw_input().split())
ans = Decimal(0)
if N > K:
	ans += Decimal(N-K+1)/Decimal(N)
pre = min(N,K)
sisu = 1
while True:
	if(pre == 1):
		break
	now = K - (K * (2**sisu - 1))/ (2**sisu)
	if(pre > now):
		ans += Decimal(pre-now)/Decimal(N * 2**sisu)
	sisu += 1
	pre = min(now,N+1)
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
ans=max(0.0,(N+1-K)/N)
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)/N
    elif l<=N:
        ans+=p*(N+1-l)/N
    r=l-1
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:

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

def countZero(f):
    s = '{:.11f}'.format(f)
    if s.find('.') < 0:
        return -1

    n = s.split('.')[1]
    ss = str(n)
    count = 0
    for i in range(len(ss)):
        if ss[i] == '0':
            count +=1
        else:
            break
    return count
    
prob = 0
for i in range(N):
    n = N - i
    n2 = n
    count = 0
    while True:
        if n2 >=K:
            break
        count+=1
        n2 = n2*2
#     print(n, n2, count, (1/N) * pow(0.5, count))
    ans = (1/N) * pow(0.5, count)
    if countZero(ans) >= 11:
        break
    else:
        prob += ans

print(prob)

Submission status: Wrong Answer

Solution code:
n,k=input().split()
n=int(n)
k=int(k)
i=0
ii=0
ans=0.0
while i!=n:
    i=i+1
    j=i
    ii=0
    anss=1
    while j<k:
       j=j*2
       ii=ii+1
       anss=anss*1/2

    if ii!=0:
        ans=ans+anss
ans=ans/n
print(ans)

Submission status: Wrong Answer

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

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

value = 0
for i in range(1, N + 1):
	count = 0
	while True:
		if K < i * 2 ** count:
			value += 1/N * (1/2) ** count
			break
		else:
			count += 1

print(value)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import decimal
input = sys.stdin.readline
decimal.getcontext().prec = 12
dec = decimal.Decimal

s = input().split(" ")
d = int(s[0])
k = int(s[1])

sums = 0
for i in range(d):
    x = i + 1
    j = 0
    while x < k: 
        x = x * 2
        j = j+1
    sums = sums + dec(1)/dec(d) * (dec(1) /dec(2) ** dec(j))

print(sums)
#0.145833333333

Submission status: Wrong Answer

Solution code:
import math
from decimal import Decimal

order = input().split()
face = int(order[0])
goal = int(order[1])

probability = Decimal(0)

#何もしなくても勝つ確率
if face >= goal:
    probability += Decimal((face-goal+1)/face)

#goal以下の数字が出た時はgoalまでコインを振る
up = goal+1 if face>= goal else face+1
for i in range(1,up):
  kaisu = int(math.log2(goal/i) + 1)
  probability += Decimal(1/face/(2**kaisu))

print(probability)

Submission status: Wrong Answer

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

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 = int(math.log(K/n)/math.log(2))+1
    cnt += (0.5)**x / N
 
print(cnt)

Submission status: Wrong Answer

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

def ischeck(lst):
    for i in lst:
        if i > 2:
            return False
    return True

tmp = [K / i for i in range(1,N+1)]
rst = list()
for t in tmp:
    if t < 2:
        rst.append(0)
    else:
        rst.append(1)
while True:
    if ischeck(tmp):
        break
    for i,t in enumerate(tmp):
        if t >= 2:
            tmp[i] = t/2
            rst[i] += 1 
print(sum([1/pow(2, i) for i in rst])/N)

Submission status: Wrong Answer

Solution code:
import math
from fractions import Fraction

n, k = [int(elem) for elem in input().split()]
prob = 0

for i in range(1, n+1):
    tmp = int(math.log2(Fraction(k,i)))
    if tmp <= 0:
        num = 0
        prob += Fraction(1,n)
    else:
        num = tmp + 1
        prob += Fraction(1,n) * (Fraction(1,2) ** num)
print(float(prob))

Submission status: Wrong Answer

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

for i in range(1,N+1):
    if K>i:
        count.append((1/N)*((1/2)**(1+int(math.log2(K/i)))))

    else:
        no_count.append(1/N)
print(sum(count)+sum(no_count))

Submission status: Wrong Answer

Solution code:
def pows(n, K):
    count = 0
    while True:
        if n >= K:
            return count
        n = n * 2
        count += 1


def main():
    N, K = list(map(int, input().split()))
    re = max(N - K, 0) / N
    # print(re)
    for i in range(1, N + 1):
        if i >= K :
            break
        p = pows(i, K)
        # print(p)
        re = re +  pow(0.5, p) / N
    print(re)
    # print(re / N)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


NK = input().split(' ')
N = int(NK[0])
K = int(NK[1])

nn = [0] * N
ni = N
n = 1
np = 0
while ni >= 1:
    if ni * n >= K:
        nn[ni - 1] = np
        ni -= 1
        continue
    n *= 2
    np += 1

print(nn)

a = 0
for n in nn:
    a += pow(2, nn[0] - n)

a = a / (N * pow(2, nn[0]))

print('{:.10f}'.format(a))

Submission status: Wrong Answer

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

check=[0 for i in range(N+1)]

def power2(x):
    temp=1
    power=0
    for i in range(20):
        if 2**i<x:
            continue
        else:
            power=i
            return power
            break
    return power
prob=0
for i in range(1,N+1):
    if i>=K:
        prob+=(N-i+1)
        break
    temp=K//i 
    if K%i==0:
        power=power2(temp)
    else:
        power=power2(temp)+1   
    prob+=(1/2)**power
print(prob/N)

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):
  l = math.ceil(math.log(i + 1, k))
  prob = prob + 1 / n * (1 / 2**l)
  
print(prob)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n,k=map(int,input().split())

summ=0
cnt=0

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

Submission status: Wrong Answer

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

win_prob = 0

import math
if n < k:
  for i in range(1, n+1):
    win_prob += 0.5 ** int(math.log2(k / i) + 1)
  print(win_prob / n)
else:
  for i in range(1, k):
    win_prob += 0.5 ** int(math.log2(k / i) + 1)
  print(win_prob / n + (n - k + 1) / n)

Submission status: Wrong Answer

Solution code:
from math import log

n,k = (int(num) for num in input().split())
p = 1/n
ans = 0.0

def isPower(n):
    if n == 2 or n==1:
        return True
    elif n%2 == 1 or n%1 != 0:
        return False
    else:
        isPower(n//2)
    

if n >= k:
    ans += p * (n-k+1)
    for i in range(1,k):
        if isPower(k/i):
            ans += p*(1/2)**(int(log(k/i,2)))
        else:
            ans += p*(1/2)**(int(log(k/i,2))+1)
        
else:
    for i in range(1,n+1):
        if isPower(k/i):
            ans += p*(1/2)**(int(log(k/i,2)))
        else:
            ans += p*(1/2)**(int(log(k/i,2))+1)
        
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

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

Submission status: Wrong Answer

Solution code:
import math
import sys
from collections import Counter


def parse(file):
    n, k = map(int, file.readline().split())
    return n, k


def main(n, k):
    xs = []
    for i in range(n):
        d = i + 1
        if d >= k:
            xs += [0] * (n - d + 1)
            break
        x = math.ceil(math.log(k) / math.log(2 * d))
        xs.append(x)

    c = Counter(xs)
    ans = 0
    for k, v in c.items():
        ans += ((1 / 2) ** int(k)) * v

    return ans / n


if __name__ == '__main__':
    print(main(*parse(sys.stdin)))

Submission status: Wrong Answer

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

if N<K:
    pro = 0
    for n in range(N):
        if K % (2*(n+1))==0:
            X =  K / (2*(n+1))-1
        else:
            X =  K // (2*(n+1))+1
        pro += 0.5**X*(1/N)

    print(pro)

else:
    pro = (N-K+1)/N

    for n in range(K-1):
        if K % (2*(n+1))==0:
            X =  K / (2*(n+1))-1
        else:
            X =  K // (2*(n+1))+1
        pro += 0.5 ** X * (1 / N)

    print(pro)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

def is_even(x):
    if (x//2)*2 == x:
        return 1
    else:
        return 0

if __name__ == "__main__":
    N,K = map(int,input().split())
    Ks = [K]
    while K > 1:
        K = K/2
        Ks.append(math.ceil(K))
    L = len(Ks)
    for i in range(L):
        if Ks[i] <= N:
            b = i
            break
    prop = 0
    if b == 0:
        Ks.insert(0,N+1)
        for i in range(L):
            a = Ks[i] - Ks[i+1]
            prop += a /(2**i)
    else:
        Ks.insert(b,N+1)
        for i in range(b,L):
            a = Ks[i] - Ks[i+1]
            prop += a /(2**(i))
            print(a,i)
    print(prop/N)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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