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:
# -*- coding: utf-8 -*-
N, K = map(int, input().split(' '))

import math
ret = 0
log_k = math.log(K)
for n in range(1, N+1):
    prob = 1
    while n < K:
        prob *= 0.5
        n *= 2

    ret += prob


print(ret / N)

Submission status: Accepted

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

import math

prob = 0
for i in range(1, n + 1):
  a = max( 0 , math.ceil( math.log( k / i, 2 )))
  prob += ( 1 / n ) * ( 0.5 ** a )
print( prob )

Submission status: Accepted

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

Submission status: Accepted

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

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

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 += 1/n
        continue
    predict = math.ceil(math.log2(k/i))
    ans += (1/n)*((1/2)**predict)

print(ans)

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())
pro = 0.0
for p in range(1, n + 1):
    if p >= k:
        pro += 1.0 / n
    else:
        a = math.ceil(math.log2(k / p))
        pro += (1.0 / n) * (0.5**a)
print("{:.15f}".format(pro))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

prob = []

for i in range(1,n+1):
	for j in range(10000):
		#print(i,j)
		if k <= i*2**j:
			#print("1/{}*(1/2)**{}".format(n,j))
			p = (1/n)*(1/2)**j
			prob.append(p)
			break

print(sum(prob))

Submission status: Accepted

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

L = [0]*N
num =1
for i in range(N):
    num = 1
    if i < K:
        while num*(i+1) < K:
            num *= 2
        L[i]= 1/N * 1/num
    else:
        L[i] = 1/N

ans = 0
for i in range(N):
        ans +=L[i]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(1, N + 1):
    k = K / i
    streak = 0
    while k > 1:
        k /= 2
        streak += 1
    ans += (1 / N) * 0.5**streak

print(ans)

Submission status: Accepted

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


prob_sum = 0
die_prob = 1/N

def find_flips(i):
    score = i
    flips = 0
    while score < K:
        score *=  2
        flips += 1
    return flips

for i in range(1,N+1):
        #print(i, find_flips(i), math.ceil(math.log2(K/2)))    
        prob_sum += die_prob * (1/2)**(find_flips(i))

print(prob_sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math


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

    result = 0
    for i in range(1, N + 1):
        cnt = max(math.ceil(math.log(K / i, 2)), 0)
        result += (1 / N) * (1 / 2)**cnt
    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:

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

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

Pro = 0

for i in range(1, N+1):
    try:
        count = math.ceil(math.log2(K / i))
        if count < 0:
            count = 0

    except ValueError:
        count = 0

    Pro += ((0.5) ** count) / N

print(Pro)

Submission status: Accepted

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

def succ(m): #サイコロの目がmの時、kを超えるようにコインの表を出し続ける最小の回数
  res = 0
  while True:
    if m < k:
      res += 1
      m *= 2
    if m >= k:
      return res

def pos():
  res = 0
  for i in range (1, n+1):
    m = n*2**succ(i)
    res += 1/m
  return res

print(pos())

Submission status: Accepted

Solution code:
import math
tmp = 0
big_dice = 0
a,b = map(int, input().split())
log2_b = math.log2(b)
if a > b:
  c = b
  big_dice = (a - b) / a
else:
  c = a
for i in range(1, c + 1):
  log2_i = math.log2(i)
  n = math.ceil(log2_b - log2_i)
  tmp = tmp + 0.5**n
print(tmp / a + big_dice)

Submission status: Accepted

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

ans = []
for i in range(1, n + 1):
    rate = n
    score = i
    while score <= k - 1:
        score *= 2
        rate *= 2
    ans.append(1 / rate)

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=[]
def x(t,k):
  c=0
  while t<k:
    t*=2
    c+=1
  return c

for i in range(n):
  a.append(x(i+1,k))

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
y = 0
for i in range(1,n+1):
  for j in range(18):
    if i * 2**j > k-1:

      y += 1/(n*2**j)
      break
print(y)

Submission status: Accepted

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

Submission status: Accepted

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

# table[i] := 得点がi+1の時、あと何回連続でコインの表を出せばすぬけ君が勝つか
table = [None] * k

# 得点がpの時あと何回連続でコインの表を出せばすぬけ君が勝つかを求める関数
def dfs(p):
    if p >= k:
        return 0
    elif table[p-1] != None:
        return table[p-1]
    return 1 + dfs(p * 2)

ans = 0
for i in range(n, 0, -1):
    ans += pow(0.5, dfs(i))
print(ans/n)

Submission status: Accepted

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

def check(i, K) :
    b = 0
    while i < K :
        b += 1
        i *= 2
    return 0.5**b

ans = 0
for i in range(1,N+1) :
    ans += check(i,K)/N

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

N,K=[int(x) for x in input().rstrip().split()]
ans=0
m=1
for i in range(1,N+1):
    
    while(i*m<K):
        m=m*2
    
    ans+=1/(m*N)
    m=1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

for i in range(1, N + 1):
    tmp = 1 / N  # その目が出る確率
    now = i
    while now < K:
        now *= 2
        tmp /= 2
    ans += tmp  # その目でクリアできる確率
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
ans = []
for i in range(1, n+1):
    if i < k:
        j = i
        cnt = 0
        while j < k:
            j *= 2
            cnt += 1
        tmp = 1/n * ((1/2) ** cnt)
        ans.append(tmp)
    if i >= k:
        ans.append(1/n)
print('{:.10f}'.format(sum(ans)))

Submission status: Accepted

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

def probability(p):
    if p >= K:
        return 1
    cnt = 0
    while(p < K):
        p = p * 2
        cnt += 1
    return 1 / (2 ** cnt)

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import *
n,k=map(int,input().split())
e=0
for i in range(1,n+1):
  t=ceil(log2(k/i))
  e+=1*(t<1)or 2**-t
print(e/n)

Submission status: Accepted

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

Submission status: Accepted

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

pos=0
sum=0

for i in range(1,N+1):
    pos=1/N
    count=0
    while i<K:
        i*=2
        count+=1
    #print(count)
    pos*=pow(1/2,count)
    sum+=pos



print(sum)

Submission status: Accepted

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  import math
  n,k=map(int,input().split())
  ans=0
  for i in range(1,n+1):
    ans+=1/pow(2,max(int(math.ceil(math.log2(k/i))),0))         
  print(ans/n)
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  import numpy as np
  n,k=map(int,input().split())
  ans=0
  for i in range(1,n+1):
    ans+=1/pow(2,max(int(np.ceil(np.log2(k/i))),0))         
  print(ans/n)
if __name__=='__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
    score=i
    cnt=0
    while(K>score):
        score=score*2
        cnt+=1
    ans+=(1/N)*(0.5**cnt)
print("{:.12f}".format(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

p = 0
for i in range(1,n+1):
    if i < k:
        r = 1
        while i < k:
            i *= 2
            r *= 1/2
        p += r
    else:
        p += 1

print(p/n)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
prob=0
num=0
for i in range(N):
    buf=1/N
    num=i+1
    #print(i+1,K)
    if not(num>=K):
        while num<K:
            num=num*2
            buf=buf*0.5
    prob=prob+buf
print(prob)

Submission status: Accepted

Solution code:
#n=int(input())
n,k=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(1,n+1):
    p=i
    count=0
    while p<k:
        count+=1
        p=p*2
    ans+=(0.5**count)
ans=ans/n
print('{:.11f}'.format(ans))

Submission status: Accepted

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

def solve(N: int, K: int):
    inN = N
    sum = 0.0
    rate = 1.0
    if N >= K :
        sum += (N-(K-1))*rate
        N = K - 1
    while K >= 2:
        K = math.ceil(float(K)/2.0)
        rate /= 2.0
        if N > K-1:
            sum += (N-(K-1))*rate
            N = K - 1
    print(sum/float(inN))
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
    score=i
    cnt=0
    while k>score>0:
        score*=2
        cnt+=1
    ans+=0.5**cnt
ans*=1/n
print(ans)

Submission status: Accepted

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

points=[]
for i in range(N):
    x=K/(i+1)
    y=math.log(x)/math.log(2)
    y=max(0,math.ceil(y))
    z=pow(2,-math.ceil(y))
    points.append(z)
print(sum(points)/N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=0
for i in range(n+1):
    for x in range(20):
        if i*(2**x) >= k:
            a+=(1/n)*((1/2)**(x))
            break
print(a)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = float(0)
for i in range(1, n+1):
    cnt = 0
    while True:
        if i >= k:
            break
        i *= 2
        cnt += 1
    ans += 0.5**cnt
    # print(cnt)

ans *= 1 / n
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

def cnt2(x):
    cnt=0
    while x<k:
        cnt+=1
        x*=2
    return cnt

for i in range(1,n+1):
    ans+=1/(n*2**cnt2(i))
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

prob = num_of_heads =  0
for i in range(n, 0, -1):
    while i * 2 ** num_of_heads < k:
        num_of_heads += 1
    prob += (1/n) * (1/2)**num_of_heads

print(prob)

Submission status: Accepted

Solution code:
import math
n,k = [x for x in list(map(int,input().split()))]
prob = 0
for i in range(1,n+1):
    number = math.ceil(math.log(math.ceil(k/i),2))
    prob+=(1/2)**number
prob*=(1/n)
print(prob)

Submission status: Accepted

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

prob_win = 0.0
for i in range(1, N+1):
    pnt = i
    cnt = 0
    while(True):
        if pnt >= K:
            break
        pnt *= 2
        cnt += 1
    prob_win += (1/N) * (1/2)**cnt

print(prob_win)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = (int(_) for _ in input().split())
m, q, ans = (n, 0, 0)

while m > 0:
    if k <= m:
        ans += (m - k + 1)/n * 0.5**q
        m = k - 1
    k = k // 2 + k % 2
    q += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    ans = 0
    for i in range(1, N+1):
        cur = i
        cur_p = 1/N
        while cur < K:
            cur *= 2
            cur_p /= 2
        ans += cur_p
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

total = 0
win = 0
p = 0.0
for n in range(1, N+1):
  t = n
  c = 0
  while t < K:
    c += 1
    t *= 2
  p += 0.5**c * 1/N
  
print(p)

Submission status: Accepted

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

ans = 0
for x in range(1, N+1):
    if x >= K:
        ans += 1
        continue
    t = 1
    while x < K:
        x<<=1
        t<<=1
    ans += 1/t

print(ans / N)

Submission status: Accepted

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

t = 0
import math
for x in range(1, min(N,K-1)+1):
    t += (1-pow(0.5, math.ceil(math.log2(K/x))))

print(1 - t / N)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
    temp=i
    cnt=0
    while temp<k:
        temp*=2
        cnt+=1

    ans+=(1/n)*(1/2)**cnt
print(ans)

Submission status: Accepted

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

import math
ans = 0
for i in range(1, n+1):
    if i >= k:
        t = 0
    else:
        t = math.ceil(math.log2(k/i))
    #print(t)
    ans += (1/n)*((1/2)**t)
print(ans)

Submission status: Accepted

Solution code:

import math
n,k = map(int,input().split())
m = min(n, k)
win = 0#負ける確率
for i in range(1, m + 1):
    a = math.ceil(math.log2(k / i)) #a回連続で表で勝利
    win += 1 / n * pow(1 / 2, a) #iが出る確率*a回連続で表の確率
    #print(i, a, 1 / n * pow(1 / 2, a), win)
win += 1 / n * max(0, n - k) #さいころでk以上が出る確率
print(win)

Submission status: Accepted

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

from math import log,ceil

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

print(ans)

Submission status: Accepted

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

    for j in range(cnt):
        add/=2
    ans+=add

print(ans/n)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
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)/(2**(math.ceil(math.log(k/(i+1),2))))
print(ans)

Submission status: Accepted

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

from math import ceil, log2

def main():
  n, k = map(int, input().strip().split())
  p = 1/n
  s = 0
  for x in range(1, n+1):
    if x >= k:
      s += p
    else:
      s += p * (1/2 ** ceil(log2(k/x)))
  print(s)

if __name__=='__main__':
  main()

Submission status: Accepted

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

ans=0
prob=1/n
coins=1/2

for i in range(1,n+1):
    cnt=1
    tmp=i
    if tmp >= k:
        ans+=prob
    else:
        while tmp*2 < k:
            tmp=tmp*2
            cnt+=1
        ans+=prob*(coins**cnt)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    rate = 0
    for i in range(1, N + 1):
        t = 1
        while i * t < K:
            t *= 2

        rate += 1 / t

    print(rate / N)


main()

Submission status: Accepted

Solution code:
# coding: utf-8

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


class Result:
    def __init__(self, win: int, lose: int):
        self.win = win
        self.lose = lose
        self.total = win + lose


dic = {}


def get_ans(current: int):
    if current >= k:
        return Result(1, 0)
    if current in dic:
        return dic[current]
    ret = get_ans(current * 2)
    ret = Result(ret.win, ret.lose + ret.total)
    dic[current] = ret
    return ret


result_list = [get_ans(i) for i in range(1, n+1)]
max_total = max([i.total for i in result_list])

win_total = 0
lose_total = 0
for i in result_list:
    mul = int(max_total / i.total)
    win_total += i.win * mul
    lose_total += i.lose * mul

print(win_total/(win_total+lose_total))

Submission status: Accepted

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

p = 0
p += max(0,(n - k) / n)

p += sum([ 1 / n * (1 / 2 ** math.ceil(math.log2(k/x))) for x in range(1,n - max(0,n - k)+1)])

print(p)

Submission status: Accepted

Solution code:
def cal(i):
    kaisu = 0
    while(i<k):
        i *= 2
        kaisu += 1
    return (1/(n*1.0))*pow((1/2.0),kaisu)

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

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

print(ans)

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

Solution code:
def cnt(a,b):
    ret = 0
    while a < b:
        a *= 2
        ret += 1
    return ret

n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    ans += 1/n*(1/2)**cnt(i,k)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

import math
ans = 0.0
for i in range(1,n+1):
  tmp = 1/n
  a = i
  while a<k:
    a*=2
    tmp/=2
  ans += tmp
  
print(ans)

Submission status: Accepted

Solution code:
import sys 
from decimal import Decimal
readline = sys.stdin.buffer.readline
N,K = map(int, readline().split())
l = [2**i for i in range(18)]
ans = 0
for i in range(1,N+1):
  for j in l:
    if i*j < K:
      continue
    ans += 1/j
    break
print(ans/N)

Submission status: Accepted

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

Submission status: Accepted

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

# 普通に書いてよい。。？
probability = 0.0

for i in range(1,N+1) :
    toss_count = 0
    point = i
    while(K > point) :
        toss_count += 1
        point = point * 2
    
    probability += 1 / (N * pow(2,toss_count))

print(probability)

Submission status: Accepted

Solution code:
import math


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

ans = 0

for n in range(1, N+1):
    num_success = max(0, math.ceil(math.log2(K/n)))
    ans += (1/2) ** num_success

print(ans/N)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
for i in range(1, n+1):
  if i >= k:
    ans += 1/n
  else:
    for j in range(1, 20):
      if k <= i * int(pow(2, j)):
        ans += 1/n * pow(1/2, j)
        break
print(ans)

Submission status: Accepted

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

print('{:.10g}'.format(p / N))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
kouho=[i for i in range(1,N+1)]
kari=[]
count = 0
j=0
while j<len(kouho):
    if kouho[j]<K:
        count+=1
        kouho[j]*=2
    else:
        kari.append(((1/2)**count)*1/N)
        j+=1
        count=0
print(sum(kari))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(kaku)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
asn = 0
for i in range(1, n+1):
    for j in range(k):
        if i * (2 ** j) >= k:
            asn += 0.5**j
            break

print(asn/n)

Submission status: Accepted

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

for i in range(1,n+1):
    for j in range(k):
        num = j
        if i*(2**num) >= k:
            break
    ans += 0.5**num

print(ans/n)

Submission status: Accepted

Solution code:
from math import ceil, log

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

ans = 0
for i in range(1, N+1):
    val = i
    # val * 2^n > K
    # 2^n > K / val
    # n > log(K/val) / log2
    count = ceil(log(K/val) / log(2))
    count = 0 if count < 0 else count
    ans += 1 / (pow(2, count) * N)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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