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 = 0.0
for i in range(1, N+1):
    pp = 1 / N
    x = i
    while (x < K):
        pp /= 2
        x *= 2
    p += pp
print(p)

Submission status: Accepted

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

ans = 0

for i in range(1, N + 1):
  if i >= K:
    ans += (1 / N)
  else:
    temp = math.log(K / i, 2)
    nu = pow(2, math.ceil(temp))
    ans += (1 / (nu * N))
print(ans)

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
num = 0
for i in range(1,n + 1):#サイコロの出た目
    if i >= k:
        num += 1 / n
    else:
        num += (1 / (n * (2 ** math.ceil(math.log(k / i,2)))))
print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
tmp = 1
num_cnt = 0
while K > tmp :
  tmp *= 2
  num_cnt +=1
nums_list = []
for i in range(1,N+1):
  for j in range(num_cnt+1):
    if i*(2**j) >= K:
      nums_list.append(((1/2)**j))
      break
print(sum(nums_list)*(1/N))

Submission status: Accepted

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)

N, K = rl()

ans = 0
for i in range(1, N+1):
	if i >= K:
		ans += 1/N
	else:
		n = math.ceil(math.log(K/i)/math.log(2))
		ans += 1/pow(2, n)/N
print(ans)

Submission status: Accepted

Solution code:

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

print(answer/N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
a=[]
while k>1:
    a.append(k)
    k/=2
a.append(k/2)
ans=0
c=0
b=n
while n>=1:
    if n>=a[c]:
        ans+=(2**(-c))*(1/b)
        n-=1
    else:
        c+=1
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 12 23:11:33 2020

@author: liang
"""

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
import math

def main():
    N, K = map(int, input().split())
    prob = 0
    for i in range(1, N+1):
        if K / i <= 1:
            prob += 1
        else:
            coin = math.ceil(math.log2(K / i))
            prob += 0.5 ** coin
    print(prob / N)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(1, K):
    if i > N:
        break
    x = math.ceil(math.log2(K/i))
    p = (1/2)**x
    ans += p

ans *= 1/N

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N,K = mint()
ans = 0

def div2(x):
    k = 0
    while x<K:
        k += 1
        x *= 2
    return k

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

Submission status: Accepted

Solution code:
D, P = map(int, input().split())    
ans = 0.0
def func(i):
    t = 0
    while(i < P):
        i *= 2
        t += 1
    return t

for i in range(1, D + 1):
    ans += float((1/D)) * float(((1 / 2) ** func(i)))

print(ans)

Submission status: Accepted

Solution code:
#import math
#import itertools
#from collections import deque

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n,k=INTM()
    ans=0
    for i in range(1,n+1):
        temp=i
        ct=0
        while temp<k:
            ct+=1
            temp*=2
        ans+=(1/(n*(2**ct)))
    
    print(ans)


if __name__=='__main__':
    do()

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

ans = 0
for n in range(1, N+1):
    if n >= K:
        ans += 1/N
        continue
    x = math.ceil(math.log2(K/n))
    ans += (0.5**x)/N

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import log2
import decimal

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

decimal.getcontext().prec = 28

ans = decimal.Decimal(0)

for i in range(1, N+1):
    if i < K:
        power = -(-(log2(K) - log2(i))//1)
        prob = decimal.Decimal(1/((2**power) * N))
    else:
        prob = decimal.Decimal(1/N)

    #print(prob)
    ans = decimal.Decimal(ans + prob)
    #print(ans)

print(ans)

Submission status: Accepted

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

num = 0

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

print(num)

Submission status: Accepted

Solution code:
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


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


def main():
    n, k = Input()
    ans = 0
    for i in range(1, n+1):
        ans += 1/n * (1/2 ** func(i, k))
    print(ans)


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def p(n, k):
    if n >= k:
        return 1
    num = 0
    while n < k:
        n *= 2
        num += 1
    return 1 / 2 ** num

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

ans = 0
for n in range(1, N + 1):
    ans += p(n, K)

ans /= N

print(ans)

Submission status: Accepted

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

N, K = map(int, sys.stdin.readline().split())
ans = 0
for i in range(1, N+1):
    if K <= i:
        ans += 1 / N
    else:
        count = 0
        while i < K:
            count += 1
            i *= 2
        ans += (1 / N) * 0.5 ** count

print(ans)

Submission status: Accepted

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


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

Submission status: Accepted

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

ans= 0
from math import ceil,log2

for i in range(1,n+1):
    if i<k:
        a = ceil(log2(k/i))
        ans +=(1/n)*(1/2)**a
    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):
    for j in range(10**5):
        if i*2**j>=k:
            ans+=(0.5)**j/n
            break
print(ans)

Submission status: Accepted

Solution code:
def main():
    N,K = map(int,input().split())
    ans = 0
    dict = {}
    cnt = 0
    tmp = 1/N
    for i in range(N,0,-1):
        i = float(i)
        if K <= i:
            ans += tmp*(0.5**cnt)
        else:
            while True:
                K = K/2
                cnt += 1
                if K <= i:
                    break
            ans += tmp*(0.5**cnt)
    return ans

print(main())

Submission status: Accepted

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

ans = 0
for i in range(1, n + 1):
    j = i
    cnt = 1
    while j < k:
        j <<= 1
        cnt /= 2
    ans += cnt / n
print('{:10}'.format(ans))

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
P = max((N-K+1)/N,0)
cnt = 0
for k in range(1,min(N,K-1)+1):
    cnt += 2**(-math.ceil(math.log2(K/k)))
cnt = cnt/N
P += cnt
print(P)

Submission status: Accepted

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

ans = 0
j = 1.0
for x in range(N, 0, -1):
    if x >= K:
        ans += 1.0 * (1 / N)
    else:
        while x * j < K:
            j *= 2.0
        ans += (1.0 / j) * (1 / N)
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))


n,k = inpl()
res = 0
for i in range(1,n+1):
    cnt = 0
    now = i
    if i > k:
        res += 1/n
        continue
    while now < k:
        now *= 2
        cnt += 1
    res += 1/n*(1/2**cnt)
print(res)

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 * 2**cnt)

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,K = MI()
ans = 0
if N >= K:
    ans += (N-K+1)/N
for i in range(1,min(K-1,N)+1):
    a = i
    r = 0
    while a <= K-1:
        a *= 2
        r += 1
    ans += 1/(N*2**r)

print(ans)

Submission status: Accepted

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

ans = 0
twol = [0]*20
for i in range(1,n+1): 
    two = 0
    curr_i = i
    for i in range(20):
        if curr_i >= k: break
        curr_i *= 2
        two += 1
    twol[two] += 1

ans = 0
for two, cnt in enumerate(twol):
    ans += cnt/pow(2,two)
    
ans /= n
print(ans)
# for i in range(20):
#     if pow(2,i) * n >= k:

Submission status: Accepted

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

ans = 0
for n in range(1,N+1):
    k = 0
    m = n
    while m < K:
        m *= 2
        k += 1
    ans += 2**(-k)
print(ans / N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

ans = S / N
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

p = 1/n

ans = 0
for result in range(1, n+1):
    # result = 1,2,3
    k = K
    k /= result
    cnt = 0
    while k > 1:
        k /= 2
        cnt += 1
    ans += p * (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):
    prob = 1
    now = i
    while now < k:
        now = 2 * now
        prob = prob / 2
    ans += prob / n
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

p = 0

for i in range(1, N+1):
    if K >= i:
        p += 2**-(ceil(log2(K / i))) / N
    else:
        p += 1 / N

print(p)

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 * (2 ** count))

print(ans)

Submission status: Accepted

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

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

    ans += 1 / (N * 2 ** x)

print(ans)

Submission status: Accepted

Solution code:
#21 C - Dice and Coin
import math
N,K = map(int,input().split())

ans = 0
for i in range(1,N+1):
    if K//i != 0:
        a = math.log2(K/i)
        if a.is_integer():
            x = int(a)
        else:
            x = int(a) + 1
        ans += (1/N)*(1/2)**x
    else:
        ans += (1/N)
print(ans)

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
log2 = math.log10( 2)
ans = 0
for i in range(1,n+1):
    temp = i
    num = 1/n
    while temp < k:
        num /= 2
        temp *= 2
    ans += num

print(ans)

Submission status: Accepted

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

P = [1/N] * N

for i in range(N):
  score = i+1
  while score < K:
    score *= 2
    P[i-1] /= 2

print(sum(P))

Submission status: Accepted

Solution code:
import math
a = [int(s) for s in input().split()]
saikoro = a[0]
tensu = a[1]
ans = float(0)

for i in range(1, saikoro+1):
    if i >= tensu:
        ans += 1
    else:
        temp = tensu / i
        temp2 = math.ceil(math.log(temp, 2))
        ans += (1 / int((2 ** temp2)))

print(ans / saikoro)

Submission status: Accepted

Solution code:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, k = input_int_list()
    ans = 0
    for i in range(1, n + 1):
        start = i
        cnt = 0
        while start < k:
            start *= 2
            cnt += 1
        ans += 1 / (n * 2**cnt)
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0.0
for n in range(1, N+1):
  m = n
  a = 1
  while m < K:
    m <<= 1
    a /= 2
  ans += a
print(ans / N)

Submission status: Accepted

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

#コイン投げの回数
def coincnt(base,k):
    ans = 0
    while base<k:
        ans+=1
        base*=2
        
    return ans

p=0.0
for i in range(1,n+1):
    p+=(1/n)*(1/2)**coincnt(i,k)
    
print(p)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
k = 0
res = 0
flag = True
for i in range(1,N+1):
  flag = True
  mid = 1/N
  k = i
  if k >=K:
    pass
  else:
    while k<K:
      mid = mid*0.5
      k = k*2
  res += mid
print(res)

Submission status: Accepted

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

p = 0
q = 0
for j in range(N,0,-1):
  while j*(2**q) < K:
    q += 1
  p += 0.5**q
print(p*(1/N))

Submission status: Accepted

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

Submission status: Accepted

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

def return_prob(x):
  if K <= x:
    return 1
  else:
    return 1 / (2 ** math.ceil(math.log2(K/x)))

prob = 0
for i in range(1, N+1):
  prob += return_prob(i)
prob /= N
print(prob)

Submission status: Accepted

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


for i in range(1,N+1):
    count = 0
    point = i
    while(point <= K-1):
        point = point * 2
        count += 1
    possibility += 0.5**count

print(possibility / N)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,k = LI()
    num = 0
    frac = 0
    while n * 2**num < k:
        num+=1
    frac += 1/2**num
    # print(frac)

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

Submission status: Accepted

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

import math
result = 0
for i in range(1,n+1):
  num_exp = math.log2(k/i)
  num_exp = max(math.ceil(num_exp),0)
  result += (1/n) * ((1/2)**num_exp)
print(result)

Submission status: Accepted

Solution code:
import math
from fractions import Fraction

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

n,k=input2()
ans=0
for i in range(1,n+1):
	point=i
	if point>=k:
		ans+=Fraction(n-point+1,n)
		break
	else:
		tmp=math.ceil(math.log2((k/point)))
		ans+=Fraction(1,n)*Fraction(1,2**tmp)
print(float(ans))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
N,K=map(int,input().split())
pro=0
if N==1 and K==1:
    print(1)
elif N>=K:
    pro+=(N-K+1)/N
    for k in range(1, K):
        r = math.ceil(math.log(K / k,2))
        pro += 0.5**r / N
    print(pro)

else:
    for k in range(1, N+1):
        r = math.ceil(math.log(K / k,2))
        pro += 0.5**r / N
    print(pro)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

# for small
score = 0
times = []
for i in range(1, min(n + 1, k)):
    times.append(math.ceil(math.log2((k / i))))

if len(times):
    bottom_max = times[0]
    for t in times:
        score += 2 ** (bottom_max - t)
    score /= 2 ** (bottom_max) * n

# for big
big = [i for i in range(k, max(k, n + 1))]
score += len(big) / n
print('{:.10f}'.format(score))

Submission status: Accepted

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

import math
ans=0
for i in range(1, N+1):
    ans+=1/N*(1/2)**max(0,-(-math.log2(K/i)//1))
    #print(i,ans, -(-math.log2(K/i)//1))

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

print(probability)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
cnt=0
j=17
for i in range(1,n+1):
    if i>=k:
        cnt+=1
    else:
        while i*(2**j)>=k:
            j-=1
        cnt+=1/2**(j+1)
print(format(cnt/n,'.12f'))

Submission status: Accepted

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

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

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


if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(win)

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()

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

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from fractions import Fraction
N, K = map(int, input().split())
ans = 0
for i in range(N):
    s = i + 1
    p = Fraction(1, N)
    while s < K:
        s *= 2
        p *= Fraction(1, 2)
    ans += p
print(float(ans))

Submission status: Accepted

Solution code:
from decimal import Decimal, getcontext
getcontext().prec = 20
N, K = map(int, input().split())
res = 0
for p in range(1,N+1):
    cnt = 0
    q = 1
    while p*q <K:
        cnt += 1
        q *= 2
    res += Decimal(pow(1/2,cnt))
print(res/N)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import sys 
input = sys.stdin.readline

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

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

print(ans)