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:
n, k = map(int, input().split())
p = float(1 / n)

if (k > n):
    ans = 0
    loop = n

else:
    ans = float((n - k + 1) / n)
    loop = k - 1

for i in range(1, loop + 1):
    b = 0
    check = i
    while (check < k):
        check *= 2
        b += 1

    ans += float(p * 0.5 ** b)

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math
sys.setrecursionlimit(10**6)
from collections import defaultdict

n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
    if i>=k:
        ans+=1/n
    else:
        ans+=1/(n*2**int(1-1/(10**9)+math.log((k/i),2)))
#print(i,2**int(math.log((k/i),2)),ans)
print(ans)

Submission status: Accepted

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

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

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

print(sum(ans))

Submission status: Accepted

Solution code:
from math import log2, ceil

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

chance =[0]*n


for firstDice in range(1, n+1):
    if firstDice >= k:
        chance[firstDice-1] = 1/n

    else:
        chance[firstDice-1] = 1/n * (1/2)**ceil(log2(k/firstDice))

print(sum(chance))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

for n in range(1, N+1):
    tmp = n
    need = 0
    while tmp < K:
        tmp *= 2
        need += 1
    probability = 1 / 2**need
    ans += probability

print(ans / N)

Submission status: Accepted

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

ans = 0

for n in range(1, N+1):
    tmp = n
    need = 0
    while True:
        if tmp >= K:
            break
        tmp *= 2
        need += 1
    probability = 1 / 2**need
    ans += probability

print(ans / N)

Submission status: Accepted

Solution code:
import random
N, K = list(map(int, input("").split(" ")))
point = [i for i in range(1,N+1)]
pa=0
for i in point:
  p = 1/N
  while True:
    if i <= K-1:
      p *= 1/2
      i *= 2
    else:
      pa += p
      break
print(pa)

Submission status: Accepted

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

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

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

print(ans/N)

Submission status: Accepted

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

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

Submission status: Accepted

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

from fractions import math

ans=0

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

for i in range(1,n+1):
    if i<=k-1:
        exp = math.ceil(math.log2(k/i))
        p_i = (1/n) * ((1/2)**exp)
        ans += p_i

print(ans)

Submission status: Accepted

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

print(per)

Submission status: Accepted

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

total = 0
for i in range(1, n+1):
  tmp = 1 / n
  
  now = i
  while now < k:
    now *= 2
    tmp /= 2
  total += tmp
    

print(total)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial, log
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


N, K = Is()
log2k = log(K, 2)
ans = 0
for i in range(1, N+1):
    j = max(0, ceil(log2k - log(i, 2)))
    tmp = N * 2**j
    ans += 1/tmp
print(ans)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
#attention to list
for i in range(1, n+1):
    cnt = 0
    while i <= k-1:
        i *= 2
        cnt += 1
    ans += 0.5**cnt / n
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    tlst = [i for i in range(1, N+1)]
    coef = []
    for t in tlst:
        for x in range(0, 21):
            if t*(2**x) >= K:
                tmpx = x
                break
        coef.append(pow(1/2, tmpx))

    ans = 0
    for c in coef:
        ans += (1/N)*c
    print(ans)
main()

Submission status: Accepted

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

two_beki = [1]*20
for i in range(1,20):
    two_beki[i] = 2**i
#[1,2,4,8,16,32,64,128,256,512,1024,2048,8192,16384]
n = N+1
list_index = list()
for I in range(1,n):
    for J in range(20):
        if(I*two_beki[J]>=K):
            list_index.append(J) 
            # print(J,I*two_beki[J])
            break
#print(list_index)
sum_harf = 0.0
for I in list_index:
    sum_harf += 1/two_beki[I]/N
print(sum_harf)

Submission status: Accepted

Solution code:
# C - Dice and Coin

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

print(ans)

Submission status: Accepted

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

probability = 0


if N < K:
    for i in range(1,N+1):
        score = i
        cnt = 0
        while score <= K -1:
            score *= 2
            cnt += 1
        probability += (1/N) * ((1/2)**cnt)
else:
    probability += (N-K+1)/N
    for i in range(1,K):
        score = i
        cnt = 0
        while score <= K -1:
            score *= 2
            cnt += 1
        probability += (1/N) * ((1/2)**cnt)

print(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
    else:
        j = 1
        while i*2**j < K:
            j += 1
        ans += 0.5**j
        
print(ans / N)

Submission status: Accepted

Solution code:
from math import ceil

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

A = 1 / N
temp = N
count = 0
while True:
    if temp >= K:
        break
    temp *= 2
    count += 1

T = []
T.append(count)
C = 0

for i in reversed(range(1, N)):
    if i * (2 ** count) < K:
        count +=1
        T.append(count)
    else:
        T.append(count)

ans = 0
for i in T:
    ans += A * (0.5 ** i)
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 score < K:
        cnt += 1
        score *= 2
    ans += (1/N) * (1/2)**cnt

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if n >= k:
    kati = (n -(k-1))/n
else:
    kati = 0

for i in range(1, min(n+1, k)):
    total = i
    kakuritsu = 1/n
    while total < k:
        kakuritsu *= 0.5
        total *= 2
    kati += kakuritsu

print(kati)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, read().split())
ans = 0
for i in range(1, n + 1):
    cnt = 0
    while i < k:
        cnt += 1
        i *= 2
    ans += (1 / n) * pow(0.5, cnt)
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 += 0.5 ** cnt
print(ans*(1/n))

Submission status: Accepted

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

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

ans=0
while stack:
    x =stack.pop(-1)
    tmp=0
    while x<k:
        x*=2
        tmp+=1
    ans+=0.5**tmp
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):
    n=ceil(log(K/i, 2))
    if n>=0:
        ans+=(1/(N*2**n))
    else:
        ans+=1/N
    #print(n)
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
    else:
        cnt = 0
        while i < K:
            i *= 2
            cnt += 1
        ans += pow(2, -cnt)
print(ans / N)

Submission status: Accepted

Solution code:
from bisect import bisect_right as bir
N, K = map(int, input().split())

t = [K]
i = K
while i > 1:
    i += 1
    i //= 2
    t.append(i)
t.sort()
l = len(t)


def log(i):
    return l - bir(t, i)


ans = 0
for i in range(1, N+1):
    ans += 0.5**log(i)/N

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:
        cnt = 0
        t = i
        while(True):
            i *= 2
            cnt += 1
            if i >= K:
                ans += (t/N)*(1/i)
                break
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    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*(2**cnt))
    print(ans)

    
resolve()

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

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

def main():
    n,k = readInts()
    ans = 0
    # 1/N * (1/2 + 1/4 + ...)
    for i in range(1,n+1):
        prob = 1
        nk = i # 特典
        while nk < k:
            nk *= 2
            prob /=2
        ans += prob
    # 最後に 1/N
    ans /= n
    print(ans)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys

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

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

print(res / N)

Submission status: Accepted

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

import math

ans = 0
for i in range(1, N + 1):
    tmp = max(0, math.ceil(math.log2(K) - math.log2(i)))
    # print("#", i, tmp, 0.5 ** tmp)
    ans += 0.5 ** tmp

ans /= N

print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

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

Submission status: Accepted

Solution code:
def f(n):
    x = 1
    while n*2**x<K:
        x += 1
    return x
N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
    if i<K:
        ans += 2**(-f(i))/N
    else:
        ans += 1/N
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

from math import ceil,log
n,k = myinput()
ans = 0
for i in range(n):
    m = i+1
    if m<k:
        x = ceil( log(k/m,2) )
        ans += 1/n * ( (1/2)**x )
    else:
        ans += 1/n
print(ans)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    P = 0
    for i in range(1, N + 1):
        coins = 0
        k = i
        while k < K:
            coins += 1
            k *= 2
        P += pow(0.5, coins) / N
    print(P)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

ans = 0

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    answer = 0.0
    for i in range(1, n + 1):
        now = i
        count = 0
        while now < k:
            now *= 2
            count += 1
        answer += pow(0.5, count)
    answer /= n
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(cnt)/n)

Submission status: Accepted

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

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

print (ans / N)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

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

for i in range(1, N+1):
    now = i
    p = 1
    
    while now<K:
        p *= 1/2
        now *= 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):
  anss=1/n
  co=0
  j=i
  while j<k:
    co+=1
    j*=2
  anss*=1/(1<<co)
  ans+=anss
print(ans)

Submission status: Accepted

Solution code:
#C
import math
n, k = map(int, input().split())#n面ダイス 点数k以上
ans = 0
for i in range(1, n + 1):  #出目がi
    if i < k: #出目がk以下
        m = math.ceil(math.log2(k / i))
        ans += 1 / (2 ** m) / n
    else: #出目がk以上
        ans += 1 / n
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(1,n+1):
    num = 0
    p = i
    while True:
        if p >= k:
            x = (1/n) * (1/2)**num
            ans += x
            break
        p *= 2
        num += 1


print(ans)

Submission status: Accepted

Solution code:
import math


def main():
    N, K = list(map(int, input().split(' ')))
    ans = 0
    for k in range(1, N + 1):
        if k < K:
            n = math.ceil(math.log2(K / k))
            ans += 1 / (N * (2**n))
        else:
            # Only for N >= k >= K
            ans += 1 / N
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import log2

n, k = map(int, input().split())
ans = 0
for i in range(n):
    x = log2((k / (i + 1)))
    if x < 0:
        x = 0
    else:
        if x != int(x):
            x = int(x) + 1
    ans += (1 / n) * (0.5**x)
print('{:.12f}'.format(ans))

Submission status: Accepted

Solution code:
def dice_and_coin(n, k):

    ans = 0

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

    return ans

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

accuracy = 0
for i in range(1, N+1):
    for j in range(19):
        if i*(2**j) > K-1:
            accuracy += (1/N) * (1/2) ** j
            break
print(accuracy)

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)*(1/2)**cnt
print(ans)

Submission status: Accepted

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


def solve(N: int, K: int):
    s = max(0, N - K + 1) / N
    for k in range(1, min(N+1, K)):
        current_order = math.ceil(math.log(K / k, 2))
        s += (1 / 2) ** current_order / N
    print(s)
    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:
import numpy as np

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

p1 = max(N - K + 1, 0) / N
p2 = 0.
l2K = np.log2(K)
for k in range(1, min(K, N+1)):
    p2 += (0.5) ** np.ceil(l2K - np.log2(k))

print(p1 + p2 / N)

Submission status: Accepted

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

def main():
    N, K = map(int, input().split(' '))
    
    result = 1 / N * sum([math.pow(0.5, math.ceil(math.log2(K / n))) if n < K else 1.0 for n in range(1, N + 1)])
    print('{:.12f}'.format(result))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# ABC126C

n, k = map(int, input().split())
P = 0
for i in range(1, n + 1):
    if i >= k:
        P += (n - i + 1) / n
        break
    pow = 1
    while i * 2**pow < k:
        pow += 1
    P += 0.5**pow / n
print(P)

Submission status: Accepted

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

@lru_cache(maxsize=None)
def f(x):
    return f(x * 2) * 0.5 if x < K else 1

ans = fsum(f(i + 1) for i in range(N)) / N
print(ans)

Submission status: Accepted

Solution code:
N,K=list(map(int,input().split()))
per=[1/N]*N
count=0
for i in range(0,min(K-1,N)):
    per[i]=i+1
for i in range(0,min(K-1,N)):
    while True:
        count+=1
        per[i]*=2
        if per[i]>=K:
            per[i]=(1/N)*((1/2)**count)
            count=0
            break
print(sum(per))

Submission status: Accepted

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

count = 0
probability = 0
for i in range(1,n+1):
    score = i
    while score < k:
        score *= 2
        count += 1
    probability += (1/n)*(1/2)**count
    count = 0


print(probability)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
li=[k]
tmp=k
from math import ceil
for i in range(k):
    tmp/=2
    li.append(ceil(tmp))
    if tmp<1:
        break
# if n>=k:
#     ans+=(n-k+1)
#     n=k-1
now=n
for i,v in enumerate(li):
    if now>=v:
        ans+=(now-v+1)/(2**i)
        now=v-1
print(ans/n)

Submission status: Accepted

Solution code:
import math

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

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

print(output)

Submission status: Accepted

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

ans = 0
for i in range(1, n+1):
  p = 1 / n
  if i >= k:
    ans += p
    continue
  while i < k:
    i *= 2
    p /= 2
  ans += p
  
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:
    res=i; cnt=1
    while res<k: 
      res*=2; cnt/=2
    ans+=(1/n)*cnt
print(ans)

Submission status: Accepted

Solution code:
N,K =map(int,input().split())
Pi = 1/N
for i in range(100):
    if N*(2**i) >= K:
        fre = i
        break
    else:
        continue
Sum = 0
for j in range(N):
    Nu = N - j
    if (Nu*(2**fre)) >= K:
        Sum += Pi*((1/2)**fre)
    else:
        for k in range(100):
            fre += 1
            if (Nu*(2**fre)) >= K:
                Sum += Pi*((1/2)**fre)
                break
print(Sum)

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/n) * (1/2**count)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
p = 0
if N >= K:
    p += (N - K + 1) / N
    
for i in range(1, min(N + 1, K)):
    n = math.ceil(math.log2(K / i))
    p_i = (1 / N) * (0.5 ** n)
    p += p_i

print(p)

Submission status: Accepted

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

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

Submission status: Accepted

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

probSum=0
for diceNum in range(1,N+1):
    if (diceNum<K):
        numHeadNeeded = math.ceil(math.log(K/diceNum,2))
    else:
        numHeadNeeded=0
    
    prob = (1/N)*((1/2)**(numHeadNeeded))
    probSum = probSum+prob

print(probSum)

Submission status: Accepted

Solution code:
n,k = map (int,input().split())
ans = n + 0.0
s = 1
t = k-1
while t >= 1:
    a = min (t,n)
    ans -= a / 2**s
    t = (k-1) // 2**s
    s += 1
print(ans/n)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
res = []
for n in range(1, N + 1):
    # 1/n * 0.5**
    t = 0
    s = n
    while s < K:
        s *= 2
        t += 1
    res.append((1 / N) * (1 / 2 ** t))
print(sum(res))

Submission status: Accepted

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

    prob = 0
    for point in range(1, N+1):
        if point <= K - 1:
            p = (1/N) * (1/2.0)**math.ceil(math.log2(K/point)) 
            prob += p
        else:
            p = 1/N
            prob += p

    print(prob)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

ret=0
for i in range(1,n+1):
    now=i
    tmp=1/n
    while now<k:
        now*=2
        tmp/=2
    ret+=tmp 

print(ret)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, k = map(int, input().split())
ans=0
for i in range(1, n+1):
  a=1/n
  now=i
  while(now<k):
    now*=2
    a/=2
  ans+=a
print(ans)

Submission status: Accepted

Solution code:
n,k=[int(x) for x in input().split()]
ans=0
for i in range(1, n+1):
  a=1/n
  now=i
  while(now<k):
    now*=2
    a/=2
  ans+=a
print(ans)

Submission status: Accepted

Solution code:
n, k=map(int, input().split())
N=n
plist=[]
for n in range(n):
    v=n+1
    count=0
    while v<=k-1:
        v=v*2
        count+=1
    plist.append(0.5**count/N)
print(sum(plist))

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

for i in range(1, n + 1)[::-1]:
    if i >= k:
        ref += 1
    else:
        while i < k:
            i *= 2
            cnt += 1
            if i >= k:
                ref += 1/(2**cnt)
                cnt = 0
                break
print(ref/n)

Submission status: Accepted

Solution code:
n,k=[int(x) for x in input().split()]
ans=0
for i in range(n):
  a=1/n
  now=i+1
  while(now<k):
    now*=2
    a/=2
  ans+=a
print(ans)