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 = map(int, input().split())
res = 0
for num in range(1, n+1):
    if num >= k:
        res += 1/n
    else:
        res += 1/n * (1/2) ** math.ceil(math.log2(k/num))
    pass
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split()) 
 #複数文字の入力
ans = 0

for i in range(1,n+1):
  j=0 
  #カウンター設置
  while i<k:
    i*=2
    j+=1
  ans+=1/2**j
print("{:.12}".format(ans/n))

Submission status: Accepted

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

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

print(prob)

Submission status: Accepted

Solution code:
import math

N, K = map(int, input().split())
ans = 0
for n in range(1, N+1):
    _ans = 1/N
    score = n
    while score < K:
        _ans *= 1/2
        score *= 2
    ans += _ans
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

  a = (0.5**a)/N

  ans+=a
  

  
print(ans)

Submission status: Accepted

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

prob=0.0
for i in range(1,N+1):
    value = math.ceil(K / i)
    cnt = math.ceil(math.log2(value))
    prob += (1 / N / (2 **cnt))

print(prob)

Submission status: Accepted

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

p = sum(Fraction(1, 2**math.ceil(math.log2(K / n))) for n in range(1, min(N, K - 1) + 1)) / N
p += max(0, Fraction(N - K + 1, N))

print(float(p))

Submission status: Accepted

Solution code:
import math
import heapq
import sys
from collections import Counter
import numpy as np
import datetime

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#s = [input() for i in range(3)]

N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

sum=0
for n in range(1,N+1):
    if n<K:
        sum+=1/N*((1/2)**math.ceil(math.log2(K/n)))
    else:
        sum+=1/N
print(sum)

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 :
        x = -(-math.log2(k/i)//1)
        sum += (1/n) * pow(0.5,x)
    else:
        sum += (1/n)

print(sum)

Submission status: Accepted

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
  s=i
  a=1
  while s<k:
    a/=2
    s*=2
  ans+=a
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:
        r = -(-(math.log2(K) - math.log2(i))//1)
        ans += 0.5**r*(1/N)
    else:
        ans += 1/N
print(ans)

Submission status: Accepted

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

s=0
for i in range(1,n+1):
      c=0
      while k>i:
            i=i*2
            c+=1
      s+=(1/n)*((1/2)**c)
print(s)

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:
        y=1
        while True:
            x=i*2**y
            if x<k:
                y+=1
            else:
                break
        ans+=1/n*(1/2)**y
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:
        i *= 2
        cnt += 1
    ans += (1/n) * (0.5**cnt)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

N, K = [int(x) for x in input().strip().split()]
ans = 0
for n in range(1, N + 1):
  ans_ = 1 / N
  score = n
  while score < K:
    ans_ *= 1 / 2
    score *= 2
  ans += ans_
else:
  print(ans)

Submission status: Accepted

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

def print_ans(N, K):
    """Test Case
    >>> print_ans(3, 10)
    0.145833333333
    >>> print_ans(100000, 5)
    0.999973749998
    """
    prob = Decimal(1 / N)
    b = Decimal(math.log2(K))
    ans = 0
    for i in range(1, N + 1):
        if i >= K:
            ans += 1
        else:
            k = Decimal(math.ceil(b - Decimal((math.log2(i)))))
            ans += Decimal(2 ** (-k) ) 
    print(Decimal(ans * prob).quantize(Decimal('0.000000000001'), rounding=ROUND_HALF_EVEN))



if __name__ == '__main__':
    N, K = map(int, input().rstrip().split())
    print_ans(N, K)

Submission status: Accepted

Solution code:
import math

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

answer = 0

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

Submission status: Accepted

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

ans = 0

for i in range(1, n+1):
    prob = 1 / n
    focus = i
    while focus < k:
        focus *= 2
        prob *= 1 / 2
    ans += prob

print(ans)

Submission status: Accepted

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

def ct(n):
  ct=0
  while n<k:
    n*=2
    ct+=1
  return ct

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

Submission status: Accepted

Solution code:
#14:05
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
  tmp = 1
  while True:
    if i >= k:
      ans += tmp
      break
    else:
      i *= 2
      tmp /= 2
ans /= n
print(ans)

Submission status: Accepted

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

A=0
count=0
for i in range(1,N+1):
    j=i
    count=0
    while j<K:
        j=j*2
        #print(j)
        count=count+1
    else:
        A=A+(1/N)*pow(0.5,count)
        
print(A)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
X1=0
x=1
while x<=N:
  times=0
  point=x
  while point<=K-1:
    point*=2
    times+=1
  X1+=0.5**times/N
  x+=1
print(X1)

Submission status: Accepted

Solution code:
import math
import decimal

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

sum = 0

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


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

print('{:.12f}'.format(sum))

Submission status: Accepted

Solution code:
import bisect
import math
N,K = map(int,input().split(' '))
two_list = [ 2**i for i in range(18)]

rate = 0
for i in range(1,N+1):
    threshold = math.ceil(K/i) 
    two_idx = bisect.bisect_left(two_list,threshold)
    rate += 1 / N / two_list[two_idx]
print(rate)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC125 C - Dice and Coin
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    cur = i
    cnt = 0
    while cur<k:
        cur *= 2
        cnt += 1
    ans += ((1/2)**cnt)/n
print(ans)

Submission status: Accepted

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

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, k = rli()
    ans = 0
    for i in range(1, n+1):
        m = i
        prob = 1.0
        while m < k:
            prob /= 2
            m *= 2
        ans += prob
        # print(i, m, prob)
    ans /= n
    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):
    count = 0
    while i < K:
        i *= 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):
    tmp = 1 / n
    now = i
    while now < k:
        now *= 2
        tmp /= 2
    ans += tmp
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 K <= i: ans += 1 
    else:
        x = log2(K/i)
    
        ans += 2 ** -ceil(x)
    
print(1/N * ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
dice = list(range(1,N+1))
count = []
for i in dice:
    tmp = i
    t = 0
    while tmp < K:
        tmp *= 2
        t += 1
    count.append(t)
ans = []
for i in range(len(count)):
    ans.append(1/N*(1/2)**count[i])
print(sum(ans))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().split()]
win = 0
for i in range(1, n + 1):
  for j in range(k):
    if i * 2 ** j >= k:
      win += 0.5 ** j / n
      break
print(win)

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
probability = [0]*(n+1)
for i in range(1,n+1):
    score = i

    if score>k:
        probability[i] = 1/n
        continue
    
    count = math.ceil(math.log(k/i,2))
    probability[i] = 1/n * (1/2)**count

print(sum(probability))

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:
        k = ((K-1)//i) + 1
        count = 0
        while(k/2**count > 1):
            count += 1

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
cnt=0
ans1=0
cnt1=1
for j in range(1,min(n+1,k)):
    cnt=j
    cnt1=1
    for i in range(k):
        if cnt>=k:
            ans+=cnt1
            break
        cnt*=2
        cnt1/=2
print((max((n-k+1),0)+ans)/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
p=0
for i in range(1,N+1):
  b=len(bin(int(K-1)//i))-2
  if i >= K:
    b=0
  p +=1/((2**b)*N)
print(p)

Submission status: Accepted

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

scores = [0] * (n + 1)
cnts = [0] * (n + 1)

for i in range(1, (n + 1), 1):
    scores[i] = i

    while True:
        if (k <= scores[i]):
            break

        scores[i] *= 2
        cnts[i] += 1

list = list(map(lambda x: (1 / 2) ** x, cnts))
print(sum(list[1:(n + 1)]) / n)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
# MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
# from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	N, K = map(int, input().split())
	ans=0
	for i in range(1,N+1):
		a=0
		while i*(2**a)<K:
			a+=1
		ans+=(1/2**a)/N
	print(ans)
	
	
	
	
	
	
	
	
if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
# MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
# from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	N, K = map(int, input().split())
	ans=0
	for i in range(1,N+1):
		x=max(0,np.ceil(np.log2(K/i)))
		ans+=2**(-x)
	print(ans/N)
	
	
	
	
	
	
if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,n+1):
    a=0
    while i*(2**a)<k:
        a+=1
    li.append((1/n)*(1/2**a))
    
print(sum(li))

Submission status: Accepted

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

def renzoku(count, i):
    if i >= k:
        return count
    else:
        i = i * 2
        count += 1
        return renzoku(count, i)

ans = 0
for i in range(1, n+1):    
    count = renzoku(0, i)
    prob = (1/n) * ((1/2) ** count)
    ans += prob
print(ans)

Submission status: Accepted

Solution code:
def p_c():
    n, k = map(int, input().split())
    ans = 0
    m = min(n, k - 1)
    for i in range(1, m + 1):
        x = 0
        while k > i << x:
            x += 1
        ans += (1 / n) * (1 / (1 << x))
    if m == k - 1:
        ans += (n - k + 1) / n

    print(ans)
    
p_c()

Submission status: Accepted

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

Prb = [0]*N
for x in range(N):
  Pt = x +1
  Prb[x] = 1/N
  while Pt < K:
    Pt = Pt * 2
    Prb[x] = Prb[x] * 1/2

print(sum(Prb))

Submission status: Accepted

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

for i in range(n):
    a = i + 1
    for j in range(30):
        if a < k:
            a *= 2
        else:
            c = (1 / 2) ** j
            ans += b * c
            break
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    l=np.array([(1/2)**(-(-np.log2(K/i if K/i > 1 else 1)//1)) for i in range(1,N+1)])
    print(np.sum(l)/N)
        

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 2019-11-13 01:53:22(JST)
import sys
# import collections
import math 
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, k = [int(x) for x in sys.stdin.readline().split()]
        

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
i=1
sum=0.0
for i in range(1,n+1):
    cnt=k/i
    temp=1/n
    # cznt=i
    #
    # while cnt < k:
    #     cnt*=2
    #     m+=1
    # m=math.ceil(math.log2(cnt))
    m=-(-math.log2(cnt)//1)
    if i < k:
        sum+=temp * (1/2)**m
    else:
        sum+=temp
    # print(1/n * (1/2)**m)
print(sum)

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
i=1
sum=0.0
for i in range(1,n+1):
    cnt=k/i
    temp=1/n
    # cznt=i
    #
    # while cnt < k:
    #     cnt*=2
    #     m+=1
    m=math.ceil(math.log2(cnt))

    if i < k:
        sum+=temp * (1/2)**m
    else:
        sum+=temp
    # print(1/n * (1/2)**m)
print(sum)

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
i=1
sum=0.0
for i in range(1,n+1):
    # cnt=k/i
    temp=1/n
    cnt=i
    m=0
    while cnt < k:
        cnt*=2
        m+=1
    # m=math.log2(cnt)
    # m=m//1
    # m+=1
    # if i <= k:
    sum+=temp * (1/2)**m
    # print(1/n * (1/2)**m)
print(sum)

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

Submission status: Accepted

Solution code:
import numpy as np
import math

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

prob = np.maximum((N - K + 1) / N, 0)
#print(prob)

end = np.minimum(N, K-1)
#print(end)
for i in range(1, end+1):
    ratio = K / i
    num = math.ceil(math.log2(ratio))
    prob += 1 / N * (0.5 ** num)
#    print(prob)

print(prob)

Submission status: Accepted

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

MOD = 10 ** 9 + 7


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

    for i in range(1, N+1):
        c = 0
        if i < K:
            c = math.ceil(math.log(K, 2) - math.log(i, 2))
        # print(i, c, (1.0 / (2 ** c)), 1.0/N)
        ans += (1.0 / (2 ** c)) * 1.0/N

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

MOD = 10 ** 9 + 7


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

    for i in range(1, N+1):
        c = 0
        if i < K:
            c = math.ceil(math.log2(K) - math.log2(i))
        # print(i, c, (1.0 / (2 ** c)), 1.0/N)
        ans += (1.0 / (2 ** c)) * 1.0/N

    print("{0:.20f}".format(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

M = []
x = 1
while x < (10 ** 5) * 2:
    M.append(1 / x)
    x <<= 1

p1 = max((N - K + 1) / N, 0)
p = 0
for i in range(1, min(N + 1, K)):
    t = int(math.log2(K / i)) + 1
    if K % i == 0 and  (K // i) & (K // i - 1) == 0:
        t -= 1
    p += M[t]
ans = p / N + p1
print('{0:.10f}'.format(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(1, a+1):
  for j in range(10**5):
    if i*2**j >= b:
      ans += (1/a)*(1/2)**j
      break

print(ans)

Submission status: Accepted

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

needl = []
for i in range(n):
    need = max(math.ceil((math.log(k/(i+1),2))), 0) 
    needl.append(need)
    

ansl = []
for i in needl:
    ansl.append((1/2)**i * (1/n))

print(sum(ansl))

Submission status: Accepted

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

Submission status: Accepted

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

base = 1 / N
ans = 0
for n in range(1, N + 1):
    # nは出る目
    # countは2をかける回数
    count = 0
    for i in range(1,30):
        if K > n:
            n *= 2
            count += 1
        else:
            break
    else:
        ans += 0
    ans += base * ((0.5) ** (count)) # 小さいものから足していく 
            
print(ans)

Submission status: Accepted

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

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

    import math

    res = float(0.0)

    for score in range(1, N+1):
        p = float(1.0/N)
        while K > score:
            score = score * 2
            p = p/2
        res = res + p

    print(res)

# %%
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
    coeff = 0
    while score < K:
        score *= 2
        coeff += 1
    ans += (1/N)*((1/2)**coeff)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
tmp = list(map(int, input().split()))
n = tmp[0]
k = tmp[1]

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

print (ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
L=[1/N for i in range(N)]
for k in range(1,N+1):
  n=0
  while k*(2**n)<K:
    n+=1
  L[k-1]*=1/2**n
print(float(sum(L)))

Submission status: Accepted

Solution code:
import numpy as np

n, k = map(int, input().split())
e = 0
for i in range(1, n + 1):
    if i < k:
        if (np.log2(k) - np.log2(i)) == int(np.log2(k) - np.log2(i)):
            sh = int(np.log2(k) - np.log2(i))  # 何回コインを投げるか
        else:
            sh = int(np.log2(k) - np.log2(i) + 1)
        e += (1 / n) * 0.5 ** sh
    else:
        e += (1 / n)
print(e)

Submission status: Accepted

Solution code:
import math
N,K=map(int,input().split())
print(sum([0.5**max(math.ceil(math.log2(K/(i+1))),0)/N for i in range(N)]))

Submission status: Accepted

Solution code:
from math import ceil,log2
N,K=map(int,input().split())
print(sum([0.5**max(ceil(log2(K/(i+1))),0)/N for i in range(N)]))

Submission status: Accepted

Solution code:
import math
N, K =map(int, input().split())
print(sum([0.5**max(math.ceil(math.log2(K/i)),0)/N for i in range(1,N+1)]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC126C - Dice and Coin
N, K = list(map(int,input().split()))
p = 0
if N <= K:
    for i in range(1,N+1):
        count = 0
        while i < K:
            i = i*2
            count+= 1
        p += (1/(2**count))*(1/N)
    print(p)
elif N > K:
    for i in range(1,N+1):
        count = 0
        while i < K:
            i = i*2
            count+= 1
        p += (1/(2**count))*(1/N)
    print(p)

Submission status: Accepted

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

for i in range(1, a+1):
  tmp = 1
  while i*tmp < b:
    tmp *= 2
  ans += (1/a)*(1/tmp)

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from math import log,ceil
    n,k=map(int,input().split())
    p=[0]*(n+1)
    for i in range(1,n+1):
        p[i]=max(0,ceil(log(k/i)/log(2)))
    ans=0
    for i in range(1,n+1):
        ans+=2**(-p[i])
    print(ans/n)
resolve()

Submission status: Accepted

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

for i in range(1,n+1):
  x=0
  while i*(2**x)<k:
    x+=1
  a.append(x)
    
ans=0
for j in range(0,n):
  ans+=(1/n)*(2**(-a[j]))
  
print(ans)

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:
    dcnt=0
    while i<k:
      i*=2
      dcnt+=1
    ans+=(1/n)*(2**(-dcnt))
print(ans)

Submission status: Accepted

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

import math

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import math

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

p=0
for i in range(1,n+1):
  s = math.log2(k)-math.log2(i)
  s = max(0, math.ceil(s))
  
  p += (1/n)*0.5**s
  
  
print(p)

Submission status: Accepted

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

MOD = 10 ** 9 + 7

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

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

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())
ans = 0
for i  in range(1, n+1):
  c = math.ceil(math.log(k/i,2))
  if c < 0:
    c = 0
  ans += 1 / n * (0.5) ** c
print('{:.12f}'.format(ans))

Submission status: Accepted

Solution code:
import math

tol = 10 ** -9

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


def calc_exponent(k, i):
    tmp = math.log2(k / i)
    tmp2 = int(tmp)
    return tmp2 if 10 ** -10 > abs(tmp - tmp2) else tmp2 + 1


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

Submission status: Accepted

Solution code:
import math

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

    ans = 0
    for i in range(n):
        if i+1 == k:
            ans += (n-(i+1)+1)/n
            break
        num = math.ceil(math.log(k/(i+1),2))
        ans += (1/2)**num/n
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

exp = 0
tmp = 0
point= 0

for i in range(1, n + 1) :
    point = i
    tmp = 1 / n
    while point < k :
        point *= 2
        tmp /= 2
    exp += tmp

print(exp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N, K=map(int,input().split())
ansA, ansB = 0, 0
for i in range(N):
    if K/(i+1) <= 1:
        ansA += 1/N
    else:
        x = math.ceil(K/(i+1))
        y = 0.5**math.ceil(math.log2(x))
        ansB += y/N

print(ansA + ansB)

Submission status: Accepted

Solution code:
import math

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

res = 0
for i in range(N):
    now_points = i+1
    a = 1 / N
    while now_points <= K-1:
        now_points *= 2
        a /= 2
    res += a

print(res)

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
#S = list(input())
ans = []
for i in range(1, N+1):
    if i < K:
        ans.append(1/N * (0.5) ** (math.ceil(math.log2(K/i))))
    else:
        ans.append(1/N)
print(sum(ans))

Submission status: Accepted

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