Problem:


Score : 300 points

Problem Statement

Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:

Throw the die. The current score is the result of the die.

As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.

The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.

You are given N and K. Find the probability that Snuke wins the game.

Constraints

1 ≤ N ≤ 10^5

1 ≤ K ≤ 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.

Sample Input 1

3 10

Sample Output 1

0.145833333333

If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^4 = \frac{1}{48}.

If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^3 = \frac{1}{24}.

If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^2 = \frac{1}{12}.

Thus, the probability that Snuke wins is \frac{1}{48} + \frac{1}{24} + \frac{1}{12} = \frac{7}{48} \simeq 0.1458333333.

Sample Input 2

100000 5

Sample Output 2

0.999973749998



Sample input:
3 10


Sample output:
0.145833333333

Submission status: Accepted

Solution code:
import math

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

prob = 0

for i in range(n):
    
    num = math.ceil(math.log2(k/(i+ 1)))
    
    if num < 0:
        num = 0
    prob += 1 / n * ((1 / 2) ** num)
    
print(prob)

Submission status: Accepted

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

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

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: Accepted

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

import math
Ans = 0

if K < N:
    for X in range(1, K+1):
        R = math.log(K/X, 2)
        S = math.ceil(R)
        Ans = Ans + (0.5**S / N)
    Ans = Ans + (N-K)/N
    print(Ans)

if K == N:
    for X in range(1, K+1):
        R = math.log(K/X, 2)
        S = math.ceil(R)
        Ans = Ans + (0.5**S / N)
    print(Ans)
    
if K > N:
    for X in range(1,N+1):
        R = math.log(K/X, 2)
        S = math.ceil(R)
        Ans = Ans + (0.5**S / N)
    print(Ans)

Submission status: Accepted

Solution code:
import math 

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

result = 0

for i in range(1,n+1):
	if i < k :

		log_i = math.log2(k/i)
		ceil_i = math.ceil(log_i)

		result += math.pow(0.5, ceil_i)/n

	else:
		result += 1/n

print(result)

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
limit = 1 / n
ans = 0
for x in range(1 , n + 1):
    num = math.pow(2, -1 * math.ceil(math.log(k / x, 2)))
    num = num / n
    if num > limit:
        num = limit
    ans = ans + num
    if ans >= 1:
        break
print("{:.12f}".format(ans))

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    res = 0
    t=0
    for i in range(1, n + 1):
        count = 0
        j = i
        while (j < k):
            j *= 2
            count += 1
        if i == 1:
            t = count
            res += 1
        else:
            res += 2 ** (t - count)
    res = res/((2**t) *n)
    print(res)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
import math
n,k=list(map(int,input().split()))
sum1=0
for i in range(1,n+1):
    if i>=k:
        sum1+=1/n
        
    else:
        
        res=math.log(k/i,2)
        res=math.ceil(res)
        sum1+=(1/n)*(0.5**res)
print(sum1)

Submission status: Accepted

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

a = math.fsum([(1/n) * ((1/2)**math.ceil(math.log(k/i, 2))) for i in range(1, min(k, n+1))])

if n >= k:
    print(a + (n+1-k)/n)
else:
    print(a)

Submission status: Accepted

Solution code:
import math

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

ans/=n

print(ans)

Submission status: Accepted

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

f = 0
ans = 0

if N >= K:
    ans = (N - K + 1) / 1.0
    f = 1
K = K - 1

a = []
i = 0
while(2 * N < K):
    a.append(0)
    i += 1
    K = K // 2

if f == 0:
    i += 1
    a.append(N - K //2)
    K = K // 2

while(K != 0):
    a.append(K - K // 2)
    i += 1
    K = K // 2

bunsi = 0

for j in range(len(a)):
    bunsi += a[j] * pow(2, i - j - 1)
ans += bunsi / pow(2, i)

print(ans / N)

Submission status: Accepted

Solution code:
import math
a, b = (int(_) for _ in input().split())  
res = float(sum([(1/2 ** (math.ceil(math.log2(b/i)))) if i < b else 1 for i in range(1,a+1)]) / a)
print(res)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
ans = 0
for p in range(1,min(N+1,K+1)):
    for q in range(1,K+10):
        if 2**(q-1) * p <= K - 1 and 2**q * p >= K:
            ans += (1/N)*(1/2)**q
            break
if N < K:
    ans = ans
else:
    ans += (N-(K-1))/N
print(ans)

Submission status: Accepted

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:
    r=1-(k/n)
    for i in range(1, k+1):
        r=r+(1/n)*0.5**math.ceil(math.log2(k/i))
    print(r)

Submission status: Accepted

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

ans = 0

if N >= K:
    ans += (N - K + 1) / N
n = K - 1


tmp = 2
while n >= 1:
    a = 0
    if n == 1:
        a = 1 / tmp / N
    else:
        if n > N:
            if n % 2 == 1 and n // 2 < N:
                a = (N - n // 2) / tmp / N
            if n % 2 == 0 and n // 2 < N:
                a = (N - n // 2) / tmp / N
        else:
            a = (n - (n // 2)) / tmp / N
    tmp *= 2
    n //= 2
    ans += a
    #print(a)

print(ans)

Submission status: Accepted

Solution code:
import math

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

total = 0
for d in range(1, N + 1):
    if d < K:
        ceil = math.ceil(math.log2(K) - math.log2(d))
        total += 1 / (2 ** ceil)
    else:
        total += 1

print(total / N)

Submission status: Accepted

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(1,100):
            if pow(2,j)>=(k/i):
                kaisu.append(1/2**j)
                break
ans=sum(kaisu)/n
print(ans)

Submission status: Accepted

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)**(math.ceil(math.log2(K/i))))
print(sum)

Submission status: Accepted

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

prob = 0.0
t = 0

for i in range(1, n+1):
    point = i
    for j in range(0, k+1):
        point = i * 2 ** j
        if point >= k:
            t = j
            break
    prob += (1.0/n) * (0.5)**t

print(prob)

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import log

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

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

Submission status: Accepted

Solution code:
import math

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

ans = 0
for i in range(N):
    n = math.log2(k) - math.log2(i+1)
    if n < 0:
        n = 0
    if n > 0:
        n = math.ceil(n)
    ans = ans + 1/((2**n)*N)
print(ans)

Submission status: Accepted

Solution code:
import math

def func(x, k):
    j = 0
    while x < k:
        x *= 2
        j += 1
    return j

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

for i in range(1, N+1):
    P.append(1/N * (1/2)**func(i, K))



print(sum(P))

Submission status: Accepted

Solution code:
a = map(int,input().split())
a = list(a)
for l in range(2):
    a[l] = int(a[l])
c = 0
b =[]
for i in range(1,a[0]+1):
    j = 0
    while True:
        infer = a[1]/i
        refer = (2)**j
        if refer >= infer:
            c = (1/refer)/a[0]
            b.append(c)
            break
        else:
            j += 1
print(sum(b))

Submission status: Accepted

Solution code:
import math
import sys
from decimal import *
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()
getcontext().prec = 80
ans = Decimal(0)
ans2 = Decimal(0)
for i in range(1, n+1):
    if i == k:
        break
    ans += (Decimal((1/n)) * Decimal((Decimal(0.5) ** math.ceil(math.log(k/i, 2)))))
if n - k + 1 > 0:
    # ans += ((1/n) * (n-k))
    ans2 += (Decimal((1/n)) * Decimal((n-k+1)))
print(ans+ans2)

Submission status: Accepted

Solution code:
import math

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

a = 0
b = []

for i in range(1, n + 1):
    v = math.ceil(math.log2(k/i))
    if v <= 0:
        b.append(1)
    else:
        b.append((1/2) ** v)

print(sum(map(lambda x: 1/n * x, b)))

Submission status: Accepted

Solution code:
S = list(map(int, input().split()))
S1 = S[0]
sum = 0
c = 0
coin = 0
for i in range(1,S[0]+1):
    k = i
    while k < S[1]:
        c = c + 1
        k = k * 2
    sum = sum + 1/S[0] * (0.5 ** c)
    
    c = 0
print(sum)

Submission status: Accepted

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

ans = 0

while i <= N:
    j = 0
    n = 0
    while n <= K-1:
        n = i * 2**j
        j += 1
    #print(j)
    ans += 1/N * (1/2)**(j-1)
    i += 1
            
print(ans)

Submission status: Accepted

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

    sum_prob = 0

    for dice in range(1, n+1):
        if dice >= k:
            sum_prob += (1 / n)
            continue
        coin = 1
        while dice * (2 ** coin) < k:
            coin += 1

        sum_prob += (1 / n) * (0.5 ** coin)

    print(sum_prob)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
dice, target = input().split()
dice, target = int(dice), int(target)

dev = 1.0
OK = 0
rem = dice
while 1:
  if rem <= 0:
    break
  elif rem >= target:
    OK += (rem-target+1)*dev
    rem = target-1
  target = int((target+1)/2)
  dev /= 2.0
      
print('{:.10f}'.format(OK/dice))

Submission status: Accepted

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

def need(x, y): # xを何乗したらy以上になるか
  for i in range(30):
    if x*(2**i) >= y:
      return i

for i in range(n):
  ned = need(i+1, k)
  for j in range(ned):
    a += (1/2)**(j+1)
  ans = 1 / n * a
  
print(1-ans)

Submission status: Accepted

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-1
else:
    max_N = N
a_=0
for x in range(max_N):
    a_+=pow(1/2,np.ceil(np.log2(K/(x+1))))
#     print(ans)
ans += a_/N
print(ans)

Submission status: Accepted

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

def point(check):
    count = 0

    while check < K:
        count += 1
        check = check * 2

    return 2**count


for i in range(N):
    temp = point(i+1)
    deno += 1/(N*temp)

print(deno)

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
def solve():
    n, k = map(int, input().split())
    ps = 0.0
    for i in range(1, n+1):
        sum = i
        p = 1.0 / n
        while(sum < k):
            p /= 2.0
            sum *= 2
        ps += p
    print(ps)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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
        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: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
n, k = map(int, input().split())
import math
import numpy as np
pro = 0
for i in range(1,n+1,1):
    if i < k:
        #print("i", i)
        #print(math.ceil(np.log2(k/i)))
        pro += 0.5**math.ceil(np.log2(k/i))
    else:
        pro += 1
print(pro/n)

Submission status: Accepted

Solution code:
import math

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

win = 0.
prob = 1 / n
for i in range(1, n + 1):
    if i >= k:
        win += prob
        continue
    board = math.log2(k) - math.log2(i)
    head = math.ceil(board)
    win += prob * (0.5 ** head)

print(win)

Submission status: Accepted

Solution code:
import math

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

tmp=0

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

Submission status: Accepted

Solution code:
import math


N, K = map(int,input().split())
ans = 0
for i in range(1,N+1):
    n = math.ceil(math.log2(K/i))
    if i <= K:
        ans += pow(0.5,n) / N
    else:
        ans += 1 / N

print(ans)

Submission status: Accepted

Solution code:
N, K = input().split()
N = int(N)
K = int(K)
ans = float(0)
gro_bairitu = 1


def probability(num, K, pro, loc_bairitu):
    global ans, gro_bairitu
    if num >= K:
        ans += pro
    else:
        loc_bairitu *= 2
        if loc_bairitu > gro_bairitu:
            gro_bairitu = loc_bairitu
        probability(2 * num, K, float(pro) / 2, loc_bairitu)


for i in range(N, 0, -1):
    probability(i, K, float(1) / N, gro_bairitu)

print("{:.10f}".format(ans))

Submission status: Accepted

Solution code:
import math
[N,K] = list(map(int, input().split()))
#S = str(input())        
#S = "1700"
ans = 0
#[N,K] = [100000, 5]
for i in range(1,N+1):
    if i >= K:
        ans += 1/N
    else:
        max_coin = math.ceil(math.log(K/i,2))
        ans += (0.5)**max_coin/N
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# abc126/abc126_c
import sys
from math import *

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))



def main():
    N, K = i2nn()
    if N >= K:
        s = N - K + 1
        n = K
    else:
        s = 0
        n = N + 1
    for d in range(1, n):
        s += 2**(-ceil(log2(K/d)))
    print(s/N)

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


N, K = map(lambda x: int(x), input().split())
sum = 0

if(N < K):
    edited_N = N
else:
    edited_N = K - 1

for i in range(1, edited_N + 1):
    num = math.ceil(math.log(K/i, 2))
    sum += 0.5 ** num


sum = sum * (1 / N)
if(N >= K):
    sum += (N - edited_N) / N
print(sum)

Submission status: Accepted

Solution code:
import math
N,K=map(int, input().split())
print(sum(map(lambda x: 0.5**max(0.0, math.ceil(math.log(K/x, 2))), range(1, N+1)))/float(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
data = [int(s) for s in input().split()]
sum = 0
for i in range(1, data[0]+1):
  if i >= data[1]:
    sum += 1/data[0]
  else:
    l = (math.ceil(math.log2(data[1]/i)))
    sum += (1 / data[0]) * (1/2) ** l
print(sum)

Submission status: Accepted

Solution code:
import math

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

if N >= K:
  odd += (N-K+1)/N
  for i in range(K-1):
    if (math.log2(K/(i+1)))%1==0:
      odd += (i+1)/(K*N)
    else:
      odd += (1/N)*(0.5**(int(math.log2(K/(i+1)))+1))
else:
  for i in range(N):
    if (math.log2(K/(i+1)))%1==0:
      odd += (i+1)/(K*N)
    else:
      odd += (1/N)*(0.5**(int(math.log2(K/(i+1)))+1))
      
print(odd)

Submission status: Accepted

Solution code:
import math

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

if N > K:
    ans += (N - K) / N

for i in range(min(N, K)):
    logk = math.ceil(math.log2(K / (i+1)))
    ans += 1 / N * (0.5 ** logk)

print(ans)

Submission status: Accepted

Solution code:
import math
n,k = map(int, input().split())
res = float(0)
orig = math.ceil(math.log2(k) )
count = 0
for i in range(1, n+1):
    if i > k:
        count += pow(2,orig)
    else:
        # iからスコアがk以上になるにはt回連続で表じゃないといけない
        t = math.ceil(math.log2(k) - math.log2(i))
        tt = pow(2, orig - t )
        count += tt
res = count / (n*pow(2,orig))
print(res)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
answer = 0
for i in range(N):
  dice = i + 1
  time = 0
  if dice >= K:
    answer += 1/N
    continue
  else:
    while (True):
      dice=dice*2
      time+= 1
      if dice >= K :
        answer += (1/N)*((1/2)**time)
        break
print(answer)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
def dice_coin(N,K):
    pro=[]
    for i in range(N):
        count=0
        j=0
        while K-(i+1)*2**j>0:
            j=j+1
        pro.append(1/N*(1/2)**j)
    return sum(pro)
print("{}".format(dice_coin(N,K)))

Submission status: Accepted

Solution code:
#-*- coding: utf-8 -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime
import re

def howmany_power(n, k):
    if n >= k:
        return 0
    else:
        return howmany_power(n*2, k) + 1


def sol(N, K):
    P = 0
    for n in range(1, N+1):
        if n < K:
            x = howmany_power(n, K)
            tmp = 2**x
            fst = N
            #print("n:%s, K:%s, P:%s, x:%s, tmp:%s, fst:%s" % (n, K, P, x, tmp, fst))
            P += (1/tmp)*(1/fst)
        else:
            #print("n:%s, K:%s, P:%s" % (n, K, P))
            P += (1.0/N)
    return P


do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    #print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    #S = parsed_lines[0][0]
    return n, k


if not do_submit:
    n, k = input_parse("""
    3 10
    """)
    print(sol(n, k))

    n, k = input_parse("""
    100000 5
    """)
    print(sol(n, k))


else:
    n, k = list(map(int, input().split()))
    #S = input()
    print(sol(n, k))

    # S = input().strip()
    # print(sol(S))

Submission status: Accepted

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


memo = {}
def times(i, count):
    if i in memo:
        return memo[i]
    if i < K: 
        ret  = times(i * 2, count + 1)
    else:
        ret = count
    memo[i] = ret - count
    return ret


ret = 0
for n in range(1, N + 1):
    t = times(n, 0)

    ret += (1/N) * pow((1/2), t)

print(ret)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
t = []#i / 分母
j = 0
for i in range(N,0,-1):
    while i * (2**j) < K:
        j += 1
    t.append((i,j))

ansU = 0
ansD = (2**j)*N
for i,n in t:
    ansU += 2**(j-n)
print(round(ansU/ansD,10))

Submission status: Accepted

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


def cc(n):
    i = 0
    while True:
        if K <= (n * (2 ** i)):
            return i
        i += 1


A = 0
for n in range(1, N+1):
    A += 1.0 / N * (0.5 ** cc(n))
print(A)

Submission status: Accepted

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

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

out = 0

for i in range(N):
    l = i + 1

    if l < K:

        d = l
        count = 0

        while d < K:
            d = d * 2
            count += 1
        
        # print("d:" + str(d))
        # print("count:" + str(count))

        ans = 1 / N * pow(1/2, count)
        out += ans
    else:
        ans = 1 / N * pow(1/2, 0)
        out += ans

# print(out)
# print(f'{out:f}')
# print("%f" % out)
print("{0:.12f}".format(out))

Submission status: Accepted

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

x = 2
count = 1
while(True):
    if x < K:
        x = x * 2
        count += 1
    else:
        break

ans = 0

for i in range(1, N+1):

    if 2 ** (count - 1) * i >= K:
        count -= 1
        if count == 0:
            ans += N-i+1
            break

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

Submission status: Accepted

Solution code:
import math
def AAA(s,k):
    a = 1
    while s*math.pow(2,a) < k:
        a = a+1
    return a
def Coin(n,k):
    s = [i+1 for i in range(n)]     
    b = list(map(lambda a:AAA(a,k) if a<k else 0,s))
    res = list(map(lambda a:(1/n)*math.pow(1/2,a) if a!=0 else 1/n,b))
    return sum(res)
n,k = map(int, input().split())
print(Coin(n,k))

Submission status: Accepted

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

result = 0

for i in range(n):
    i += 1
    j = 0
    while(i < k):
        j += 1
        i = i * 2

    result += 1/n * ((1/2) ** j)

print(result)

Submission status: Accepted

Solution code:
import math
from decimal import Decimal

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

win_p = []

for n0 in range(1, n+1):
    if k <= n0:
        win_p.append(1)
        continue
    x = math.ceil(math.log2(Decimal(str(k)) / Decimal(str(n0))))
    win_p.append(Decimal(0.5)**x)

print('{:.9f}'.format(sum(win_p) / n))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import math
N,K=map(int,input().split())
p=[0 for i in range(20)]
for i in range(20):
  M=K
  for j in range(i):
    M=M/2
  p[i]=math.ceil(M)
t=N+1
i=0
A=0
ans=0
while p[i]>N:
  i+=1
while p[i]!=1:
  s=p[i]
  ans+=((t-s)/2**i)/N
  t=s
  i+=1
s=p[i]
ans+=((t-s)/2**i)/N
print(ans)

Submission status: Accepted

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

ka = 0

for i in range(1, n+1):
    
    if(i >= k):
        # print(i, k, (n+1-i))
        
        ka += 1 * (n+1-i)
        break
    
    else:
        j = 1
        while(1):
            if (i * (2 ** j)) >= k:
                break
        
            j += 1
    
        ka += 1 * ((1/2)**j)
        
        # print(n, k, i, j, ka)
    
    # rint(n, k, i, j, ka)
    
print(ka/n)

Submission status: Accepted

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

for i in range(1,n+1):
    count = 0
    while True:
        if i*2**count < k:
            count += 1
        else:
            score.append(count)
            break

for s in score:
    res += (1/n)*((1/2)**s)

print(res)

Submission status: Accepted

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

clist = []
for i in range(1,N+1):
    a = i
    c = 0
    while(a<K):
        a *= 2
        c += 1
    clist.append(c)

import numpy as np
X = np.array(clist)
Y = np.array([0.5]*N)

print(sum(Y**X*(1/N)))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
lst=[]
for m in range(1,n+1):
  a=1
  cnt=0
  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: Accepted

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

if N == K:
  s = base
  end = K
elif N > K:
  s = (N-K+1) / N
  end = K
else:
  s = 0
  end = N+1
for i in range(1, end):
  n = math.ceil(math.log2(K/i))
  s += base * (0.5 ** n)
print(s)

Submission status: Accepted

Solution code:
import math

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

a = 0

for i in range(1, N+1):
    x = 0
    while(i * pow(2, x) < K):
        x += 1
        
    a += 1/N * pow(1/2, x)
    
print(a)

Submission status: Accepted

Solution code:
import math
n, k = [int(i) for i in input().split()]
ans = 0
for ni in range(1, n + 1):
    if ni < k:
        ans += 1 / math.pow(2, math.ceil(math.log2(k / ni)))
    else:
        ans += 1
ans /= n
print(ans)

Submission status: Accepted

Solution code:
a = input().split()
men = int(a[0])
score = int(a[1])
prob = 0
for i in range(1, men + 1):
  get = i
  count = 0
  while get < score:
    count += 1
    get *= 2
  prob += (1 / men) * ((1/2)**count)

print(prob)

Submission status: Accepted

Solution code:

N,K =map(int,input().split())
n = 0
ans = 0
L = K-1
R = N
while True:
    if L < N:
        break
    else:
        n += 1
        R = L
        L = R//2

if R > N:
    R=N

while True:
    foo = R-L
    foo /= 2**n
    ans += foo
    if L==1:
        ans += 1/(2**(n+1))
        break
    if L ==0:
        break
    R = L
    L =R//2
    n += 1
print(ans/N)

Submission status: Accepted

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

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

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

print(output)

Submission status: Accepted

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

Submission status: Accepted

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

import math

def calc_prob1(n, k):
    return (1/N) * (1/2)**(math.ceil(math.log2(k/n)))

if K == 1:
    print(1.0)
elif N < K:
    for i in range(1,N+1):
        L.append(calc_prob1(i, K))
    print(sum(L))
else:
    for i in range(1, K+1):
        L.append(calc_prob1(i, K))
    L.append((1 - K/N))
    print(sum(L))

Submission status: Accepted

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: Accepted

Solution code:
import math
N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
      X = K / i
      Y = math.log(X,2)
      if Y * 10 % 10 == 0.0:
        Y_int = int(Y)
      else:
        Y_int = int(Y) + 1
      if i < K:
        Z = 1 / N * (0.5 ** Y_int)
        ans += Z
      else:
        ans += 1 / N

print(ans)

Submission status: Accepted

Solution code:
import math

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

def calc_p(i, k):
    if k <= i:
        return 0
    return math.ceil(math.log2(k)-math.log2(i))

print(sum([(1/n)*(1/2)**calc_p(i,k) for i in range(1,n+1)]))

Submission status: Accepted

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

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

S = 0.0
if N >= K:
	S += (N-K+1)/N
for i in range(L):
	T = math.ceil(K/2**i)
	B = math.ceil(K/2**(i+1))
#	print(i,"N",N,"T",T,"B",B,"T-B",(T-B),"1/2**(i+1)",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: Accepted

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


def solv(n, k):
    d = np.arange(1, n+1, dtype='float64')
    p = np.fmax(k / d, 1)
    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)