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:
def main():
    n, k = map(int, input().split())

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

getcontext().prec = 12


list_prob = []
for n in range(1,N+1):
  prob = Decimal("1.0")
  while n <= K-1:
    n *= 2
    prob = prob * Decimal('0.5')
    
  list_prob.append(prob)

sum_list = Decimal(str(sum(list_prob)))
len_list = Decimal(str(len(list_prob)))

ave = sum_list / len_list
print(ave)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def c_dice_and_coin(N, K):
    ans = 0.0
    for i in range(1, N + 1):
        tmp = 1
        p = 0
        while i * tmp < K:
            tmp *= 2
            p += 1
        if p >= 50:
            continue
        ans += 1 / (2**p)
    ans /= N
    return ans

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

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int, input().split())
n = np.arange(N)+1
x = np.ceil(np.log2(np.maximum(K / n, 1)))
y = 2 ** (-x)
z = np.sum(y)/N
print(z)

Submission status: Accepted

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

Submission status: Accepted

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

m = []
for i in range(1,n + 1):
    counter = 0
    while True:
        if i >= k:
            m += [counter]
            break
        else:
            i = i*2
            counter += 1
ans = 0
for i in m:
    ans += (1/n) * ((1/2) ** i)

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

ans /= N
print('{:.10f}'.format(ans))

Submission status: Accepted

Solution code:
import math

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

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

print(p)

Submission status: Accepted

Solution code:
def solve(N, K):
    b = 1 / N
    poss = [b for _ in range(N + 1)]
    for n in range(30):
        for i in range(N + 1):
            if i == 0:
                continue
            if (i << n) < K <= (i << n + 1):
                poss[i] = b * (0.5 ** (n + 1))
    return "{:1.12f}".format(sum(poss[1:]))

if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    print(solve(N, K))

Submission status: Accepted

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

ret = 0
for i in range(1, n+1):
    cnt = 0
    total = i
    while total < k:
        total *= 2
        cnt += 1
    ret += 1./n * (1./2)**(cnt)
print(ret)

Submission status: Accepted

Solution code:
import math
N,K=map(int,input().split())
KAKURITU=0
for arufa in range(1,N+1):
  x=math.log(K/arufa,2)
  x=math.ceil(x)
  if x>=1:
    KAKURITU+=(1/N)*(1/2)**x
  else:KAKURITU+=(1/N)
print(KAKURITU)

Submission status: Accepted

Solution code:
import sys
import collections
from collections import Counter
from collections import deque
from collections import defaultdict
import itertools
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from itertools import takewhile
from itertools import compress
import functools
from functools import reduce
import math
####from math import gcd
####from math import inf
from math import ceil
from math import floor
##from math import log10
##from math import log2
##from math import log
from math import factorial
import re
from functools import lru_cache

# @lru_cache(maxsize=1000)

# MOD = 10 ** 9 + 7

# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]



from decimal import Decimal

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

score = N
counter_tmp = 0
ans = 0


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

print(ans)

Submission status: Accepted

Solution code:
from math import log2, ceil

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

ans = 0

def cal(n):
    l = ceil(log2(K/n))
    if n >= K:
        return 1/N
    return pow(2,-l)/N

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

p = 0
for i in range(1, n+1):
    m = max(math.ceil(math.log(k/i, 2)), 0)
    pi = (1/n) * (1/(2**m))
    p += pi

print(p)

Submission status: Accepted

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

Submission status: Accepted

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

def f(X):
    ans = 0
    while (2**ans)*X < K:
        ans += 1
    return ans

b = 0.0
for i in range(1,N+1):
    b += 1/(2**f(i))

print("{:.10}".format(b/N))

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
from math import ceil

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

N,K =  ints_raw()
def main():
    ans = 0
    buf = 0
    for n in range(N,0,-1):
        tmp  =n*(2**buf)
        if tmp< K:
            while tmp < K:
                tmp *=2
                buf+=1
        ans += (0.5)**(buf)
    return ans/N

print(main())

Submission status: Accepted

Solution code:
import math
a=list(map(int,input().split()))
total=0
K=a[1]
if a[0]>=a[1]:
    tmp=a[1]
    total+=a[0]-a[1]+1
else:
    tmp=a[0]+1
    
for i in range(1,tmp):
    hoge=K/i
    total+=1/pow(2,math.ceil(math.log(hoge,2)))
print(total/a[0])

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
sum_p = 0
for first_score in range(1,n+1):
    if first_score >= k:
        sum_p += 1/n
        continue
    sum_p += (1/n )*((1/2)**math.ceil(math.log2(k/first_score)))
print(sum_p)

Submission status: Accepted

Solution code:
import math

n,k=map(int,input().split())
ans=0
cnt=0
a=n
while n>0:
    if n>=k:
        ans+=(n-k+1)/a*(1/2)**cnt
        n=k-1
    k=math.ceil(k/2)
    cnt+=1
    #print(n,k,ans)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math

def main():
    N, K = map(int, input().split())
    prob = 0
    for i in range(1, N + 1):
        score = i
        if (score >= K):
            left = N - score + 1
            prob += left / N
            break
        else:
            num = 1
            while(True):
                if (score * 2 < K):
                    num += 1
                    score *= 2
                else:
                    prob += 1/(N * (2)**num)
                    break
    print(prob)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

def main():
    N, K = [int(n) for n in input().split()]
    needed = (math.log2(K))

    nex = 2
    res = 0
    for i in range(1, N+1):
        if i >= K:
            res += 1
            continue
        res += math.pow(0.5, math.ceil(needed-math.log2(i)))
        # print(math.pow(0.5, math.ceil(needed-math.log2(i))))
    res /= N * 1.
    print(res)
main()

Submission status: Accepted

Solution code:
import numpy as np
import math

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

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

Submission status: Accepted

Solution code:
import math

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

cnt = 0

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

Submission status: Accepted

Solution code:
import sys
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
print (ans/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:
        # print(i,math.ceil(math.log2(k/i)))
        times=math.ceil(math.log2(k/i))
        ans+=math.pow(0.5,times)
    else:
        ans+=1
print(ans/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:
        x = math.log2(K / i)
        x = 0.5**math.ceil(x)
    else:
        x = 1
    ans += x / N
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

a = 0
for i in range(N):
  p = i + 1
  j = 0
  while p < K:
    p = p * 2
    j = j + 1

  a = a + (1 / N * 0.5 ** j)

print(a)

Submission status: Accepted

Solution code:
import math

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

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
    t = 1.0
    for j in range(1, K):
        t /= 2
        if i * 2 ** j >= K: break
    ans += (t / N)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,K = list(map(int,input().split()))
rate = 0
for i in range (N):
    count = 0
    init_num = i+1
    while init_num < K:
        init_num *= 2
        count += 1
    rate += (0.5 ** count)/N
        
print (rate)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N,K = (int(i) for i in input().split())
roots = []
hoge = K
result = 0

while hoge != 1:
    roots.append(hoge)
    hoge = math.ceil(hoge/2)

roots.append(1)

for i in range(len(roots)):
    if N >= roots[i]:
        result += (N - roots[i] + 1) / 2 ** i
        onon = i
        break

while onon < len(roots) - 1:
    result += (roots[onon] - roots [onon + 1]) / 2 ** (onon + 1)
    onon += 1

result = result / N
print(result)

Submission status: Accepted

Solution code:
N,K=(int(x) for x in input().split())
ans=0
for n in range(N):
    me=n+1
    if me>=K:
        ans=ans+(1/N)
    else:
        for j in range(20):
            me=me*2
            if me>=K:
                ji=2**(j+1)
                ans=ans+(1/N)*(1/ji)
                break
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Dice and Coin
https://atcoder.jp/contests/abc126/tasks/abc126_c

"""
import sys


from decimal import *
from math import log2, ceil

#TLE
def __solve(N, K):
    getcontext().prec = 30
    ans = Decimal(0)
    for i in range(1, N+1):
        if i >= K:
            t = Decimal (1/N)
        else:
            t = Decimal(1/N/2**ceil(log2(K/i)))
        ans += t
    return ans


def solve(N, K):
    ans = 0
    for i in range(1, N+1):
        if i >= K:
            t = 1 / N
        else:
            t = 1/N/2**ceil(log2(K/i))
        ans += t
    return ans


def main(args):
    N, K = map(int, input().split())
    ans = solve(N, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

ans = 0

for score in range(1, N + 1):
    a = 1.0 / N
    while True:
        if score >= K:
            ans += a
            break
        else:
            a *= 0.5
            score = score << 1

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:
        res=math.ceil(math.log2(k/i))
        ans+=(1/n)*0.5**res
    else:
        ans+=(n-i+1)/n
        break
print(ans)

Submission status: Accepted

Solution code:
#入力取得
N, K = map(int, input().split())

p = 0

for i in range(1, N + 1):
    point = i
    temp_p = 1/N
    while point < K:
        point = 2 * point
        temp_p = temp_p * 1/2

    p = p + temp_p


print(p)

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int, input().split())
ans = []
for i in range(N):
	pt = i + 1
	p = 1.
	while pt <= K - 1:
		pt = 2 * pt
		p = p / 2.
	ans.append(p)
ans1 = np.sum(ans) * 1. / N
print(ans1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
log2 = math.log2
ceil = math.ceil
read = input
n,k = map(int, read().split())
ans = 0.0
for i in range(1, n+1):
    if i >= k:
        ans += 1
    else :
        ans += 0.5 ** ceil(log2(k/i))
ans /= n
print('%.12f'%ans)

Submission status: Accepted

Solution code:
import numpy as np
n,k=map(int, input().split())  #複数数値入力

arr = np.arange(1,n+1)
arr_x = np.ceil(np.log2(k) - np.log2(arr))
arr_x[np.where(arr_x <= 0)] = 0
prob = ((1/n) * (0.5 ** arr_x)).sum()

print(prob)

Submission status: Accepted

Solution code:
a,b=input().split()
a=int(a)
b=int(b)
x=0.5
count=0
for i in range(1,a+1):
    dcount=0
    while 1:
        if i>=b:
            break
        i=i*2
        dcount+=1
    if dcount==0:
        count+=1/a
    else:
        count+=1/a*x**dcount
print(count)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
import sys
from math import ceil, log2
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
N, K = tuple(li())
total = 0
for i in range(1, N + 1):
    if i < K:
        total += 2 ** -ceil(log2(K/i))
    else:
        total += 1
print(total/N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

l = [1 for i in range(31)]


for i in range(1, 31):
    l[i] = l[i - 1] * 2

N, K = map(int, input().split())
P = 0.0
for i in range(1, N + 1):
    times = bisect.bisect_left(l, K/i)
    P += (1/N) * ((1/2)**times)

print(P)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N, K = map(int, input().split())
ans = 0.0
for i in range(1, N+1):
    if i < K:
        ans += 1 / N * (0.5 ** math.ceil(math.log(K / i, 2)))
    else:
        ans += 1 / N
print(ans)

Submission status: Accepted

Solution code:

"""                         
Beautiful is better than ugly.
    Explicit is better than implicit.
Simple is better than complex.
    Complex is better than complicated.
Flat is better than nested.
    Sparse is better than dense.
                    
    * Readability counts *

 // Author : raj1307 - Raj Singh
 // Date   : 19.05.19

"""

from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()

def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def li(): return list(mi())

def dmain():
    sys.setrecursionlimit(100000000)
    threading.stack_size(40960000)
    thread = threading.Thread(target=main)
    thread.start()
    
#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import ceil,floor,log,sqrt,factorial,pow,pi
#from bisect import bisect_left,bisect_right
#from decimal import *,threading

abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod,MOD=1000000007,998244353
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[0] 
def sort2(l):return sorted(l, key=getKey)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]

def powerMod(x,y,p):
    res = 1
    x %= p
    while y > 0:
        if y&1:
            res = (res*x)%p
        y = y>>1
        x = (x*x)%p1
    return res

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
    
def isPrime(n) : # Check Prime Number or not 
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) : 
        if (n % i == 0 or n % (i + 2) == 0) : 
            return False
        i = i + 6
    return True


# For getting input from input.txt file 
#sys.stdin = open('input.txt', 'r')  
  
# Printing the Output to output.txt file 
#sys.stdout = open('output.txt', 'w') 

def main():
    
    
    n,k=mi()
    prob=0
    for i in range(1,n+1):
        a=i
        c=0
        while(a<k):
            a*=2
            c+=1
        prob+=(1/n)*((1/2)**c)
        
    print(prob)
            
            
            
            
                
    
    
    
    




# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        if self.buffer.tell():
            return self.buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

# endregion

if __name__ == "__main__":
    main()
    #dmain()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
for i in range(1, n + 1):
    digit_number_difference = len(str(bin(k))) - len(str(bin(i)))
    if digit_number_difference < 0:
        ans += 1/n
        continue
    elif k > i * 2 ** digit_number_difference:
        digit_number_difference += 1
    ans += (1/n) * (1/2)**digit_number_difference
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

cnt_win = 0

for n in range(1, N + 1):
    if n >= K:
        cnt_win += 1
    else:
        num_front = np.ceil(np.log2(K / n))
        cnt_win += 1 / np.power(2, num_front)

print(cnt_win / N)

Submission status: Accepted

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

ans = 0
for i in range(1,N+1):
    x = np.log2((K-1)/i)
    if x < 0:
        ans += 1
    else:
        x = np.floor(x) + 1
        ans += (1/2)**x
        
ans /= N
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(N):

    sum = 0
    temp = i+1
    while temp < K:
        sum += 1
        temp *= 2

    ans += 1 / pow(2, sum) * 1/N
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1,N+1):
  if i < K:
    n = 0
    point = i
    while point < K:
      point *= 2
      n += 1
    ans += 1/N * (1/2)**n
  else:
    ans += 1/N
print (ans)

Submission status: Accepted

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

import sys

input = sys.stdin.readline

def main():
    n, k = [int(e) for e in input().split(" ")]
    # S = [0 for _ in range(n)]
    # for i in range(n):
    #     S[i] = 1/n if i == 0 else S[i-1] * 1/n
    #
    total_p = 0.0
    for i in range(1, n+1):
        total = i
        p = 1/n
        while True:
            if total >= k:
                total_p += p
                break
            p *= 1/2
            total *= 2

    print(total_p)


main()

Submission status: Accepted

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

p = 0.0

if K <= N:
    p += (N-K+1)/N

for init_n in range(1, min([K, N+1])):
    p += 1/N * ((1/2)**math.ceil(math.log2(K/init_n)))

print(p)

Submission status: Accepted

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

p = 0
for i in range(1, N + 1):
    t = max(math.ceil(math.log2(K / i)), 0)
    p += 1 / N * (0.5) ** t
print(p)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = 0
l = N
i = 0
while l > 0:
  b = -(-K // (2 ** i))
  _p = max(l - b + 1, 0)
  p += _p / (N * (2 ** i))
  l -= _p
  i += 1
print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from math import floor, ceil, log2
n, k = map(int, input().split())
ans = 0
for i in range(n):
    ans += 0.5 ** ceil(max(0, log2(k / (i + 1))))
print(ans / n)

Submission status: Accepted

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

ans = float(0)

for i in range(1,n+1):
    p = float(1/n)
    if i > k:
        ans += float((n-i+1)/n)
        break
    for j in range(0,20):
        if i*(2**j) < k:
            p *= float(1/2)
    ans += p

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3.4

# abc126_c

import math
from fractions import Fraction

def main():
    # input
    n, k = [int(s) for s in input().split()]
    # get ans
    sum = Fraction(0, 1)
    for i in range(1, n+1):
        mult = math.log2(k/i)
        mult = math.ceil(mult) if mult>0 else 0
        sum += Fraction(1, 2**mult)
    sum *= Fraction(1, n)
    ans = float(sum)
    # output
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def calc(n,k):
	count = 0
	while n < k:
		n *= 2
		count += 1
	return count


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

total = 0
basic = 1/n
for i in range(1, n+1):
	temp = basic
	if i < k:
		num = calc(i, k)
		temp *= (0.5)**num
	total += temp

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

print(result)

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

############

N, K = s_inpl()

ans = 0
for i in range(1, N+1):
    r = math.ceil(math.log2(K/i))
    if r<0:
        r = 0
    ans += (1/N) * ((0.5)**r)

print(ans)

Submission status: Accepted

Solution code:
import math

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

ans = 0.0
for n in range(1, N + 1):
  i = 0
  if n < K:
    i = math.ceil(math.log2(K / n))
  ans += (0.5 ** i) / N

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

Submission status: Accepted

Solution code:
def getlist():
	return list(map(int, input().split()))

N, K = getlist()

if K == 1:
	print(1)
else:
	ans = 0
	for i in range(1, N + 1):
		c = 0
		x = K / i
		while True:
			if x <= 1:
				break
			else:
				x = x / 2
				c += 1
		ans += (1 / 2) ** c
	print(ans / N)

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# a, b
# s = input()


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

i = N
while i > 0:
    if i >= K:
        ans += pow(0.5, cnt) / N
        i -= 1
    else:
        K = (K + 1) // 2
        cnt += 1
    
print(ans)

Submission status: Accepted

Solution code:
def solve(n, k):
    list1 = []
    for i in range(1, n+1):
        cnt = 0
        while True:
            if i * 2 ** cnt >= k:
                list1 += [cnt]
                break
            cnt += 1
        
    m = max(list1)
    list2 = list(map(lambda x: m-x, list1))
    list2 = list(map(lambda x: 2**x, list2))
    return sum(list2) / (n * 2**m)

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

Submission status: Accepted

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

def func(dice):
    if dice >= K:
        return 1.0
    return (1 / 2) ** math.ceil(math.log2(K / dice))

l = [func(dice) / N for dice in range(1, N + 1)]
print(sum(l))