Problem:


Score : 300 points

Problem Statement

Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:

Throw the die. The current score is the result of the die.

As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.

The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.

You are given N and K. Find the probability that Snuke wins the game.

Constraints

1 ≤ N ≤ 10^5

1 ≤ K ≤ 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.

Sample Input 1

3 10

Sample Output 1

0.145833333333

If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^4 = \frac{1}{48}.

If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^3 = \frac{1}{24}.

If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^2 = \frac{1}{12}.

Thus, the probability that Snuke wins is \frac{1}{48} + \frac{1}{24} + \frac{1}{12} = \frac{7}{48} \simeq 0.1458333333.

Sample Input 2

100000 5

Sample Output 2

0.999973749998



Sample input:
3 10


Sample output:
0.145833333333

Submission status: Accepted

Solution code:
import numpy as np

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

times = np.zeros(N + 1, dtype=np.float)

for i in range(1, N + 1):
	if i < K:
		times[i] = np.ceil(np.log2(K / i))
	else:
		times[i] = 0


print(np.sum(0.5 ** times[1:] / N))

Submission status: Accepted

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

kakuritu = 0

for i in range(N):
    tokuten = i+1
    mokuhyou = tokuten
    cnt = 0
    while mokuhyou < K:
        mokuhyou += tokuten
        tokuten *= 2
        cnt += 1
    kakuritu += (1/N)*(1/(2**cnt))

print(kakuritu)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

p = 0

t = 0
while 2**t < k:
    t += 1

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

p = p / n / 2**t

print(p)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
AtCoder C
"""
import math
# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = int(input()) for _ in range(N) # 1 row N column
 
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
 
def main():
    N, K = list(map(int,input().split()))
    # N=float(N)
    K=float(K)

    out=0
    for n in range(1,N+1):
        # print(n)
        if n>=K:
            out+=1/float(N)
        else:
            tmp=math.log2(K/n)
            # print(n,0.5**math.ceil(tmp))
            out+=0.5**math.ceil(tmp)/float(N)
    print(out)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

import math

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

# 1. サイコロを振って得点にする
# 2. 得点がKより小さいならコインを振る
#   1. コインが裏なら負け
#   2. コインが表なら得点は2倍に
# 出す目それぞれについて、Kを超えるのに必要な2倍の数を求めて足し合わせる

# a2^n > K ⇔ nlog2 +loga > logK ⇔ n > (logK-loga) / log2
# aについて、勝利できる確率はn回表を出す=1/2^n
# あとはaについて1/Nを掛けて足し合わせればOK

p = 0.0

for i in range(1, N+1):
    if K > i:
        n = math.log(K/i) / math.log(2)
        n = math.ceil(n)
        p += (1/2**n) / N
    else:
        p += 1/N

print(p)

Submission status: Accepted

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

ans = 0

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

p = 0
for m in range(1,N+1):
  if m>=K:
    p+=1/N
  else:
  	p += 0.5**math.ceil(math.log2(K/m)) / N

print(p)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

    ans = 0
    for i in range(1, N+1):
        if i >= K:
            ans += (1/N)
            continue
        # a*2^n >= K より
        # n >= log2(K/a)
        n = math.ceil(math.log2(K/i))
        ans += (1/N) * (1/2)**n

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
from math import log2,ceil,pow
N,K = map(int,input().split())
ans = 0
for n in range(1,N+1):
    num = ceil(log2(ceil(K/n)))
    rate = (1/N)*pow(1/2,num)
    ans += rate
print(ans)

Submission status: Accepted

Solution code:
from math import log2
from math import ceil

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

a = list(map(ceil, [0 if (n >= K) else log2(K/n) for n in range(1, N+1)]))
a = [(1/N) * (1/2)**n for n in a]

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

prop = 0

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

print(prop)

Submission status: Accepted

Solution code:
import math

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

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

print(ans/n)

Submission status: Accepted

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

prob = 0
for n in range(1, N+1):
    i = 0
    while (2 ** i) * n < K:
        i += 1
    #print(n, i)
    prob_a = 1.0 / float(N) * (1 / 2**i)
    #print(prob_a)
    prob += prob_a
print(prob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

listNK = list(map(int,input().split()))
N = listNK[0]
K = listNK[1]

output = 0

for i in range(N):
    X = i+1
    if X>=K:
        output += 1/N
    else:
        n = math.log2(K/X)
        n = math.ceil(n)
        output += (1/N)*(1/2)**n

print(output)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    import math

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

    ans = 0

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

    print(ans/n)

Submission status: Accepted

Solution code:

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

n0=n
i=0
kai = []
while(k!=1):
    kai.append(max(0,n-k+1))
    if n >= k:
        n = k-1
    k=(k+1)//2
kai.append(1)

#print(kai)

ans = 0.0
for i,c in enumerate(kai):
    ans += c*2**(-i)
#    print(ans)
print(ans/n0)

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0
# サイコロの出た目がiの時
for i in range(1, N+1):
    j = 0
    probability = 1
    score = i
    while score < K:
        # 表が出たら2倍
        score *= 2
        probability *= 0.5
    sum += ( probability / N )

print("{}".format(sum))

Submission status: Accepted

Solution code:
import math

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

expNum = math.ceil(math.log(K, 2))
# print(expNum)
possibility_arr = []

for i in range(N):
    num = i + 1
    if num < K:
        tempNum = K/num
        expNum = math.ceil(math.log(tempNum, 2))
        poss = 1/N * 1/2**expNum
    else:
        poss = 1/N
    #print(poss)
    possibility_arr.append(poss)

# print(possibility_arr)

print(sum(possibility_arr))

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

def calc(dise, k):
    return (1/2) ** math.ceil(math.log2(k/dise))

ans = 0

for i in range(n):
    if i+1 >= k:
        ans += 1/n
    else:
        ans += calc(i+1, k) / n
print(ans)

Submission status: Accepted

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

print(result)

Submission status: Accepted

Solution code:
import sys, os
import math

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, k = f()
    ans = 0
    for i in range(1,n+1):
        if i<k:
            num = int(math.ceil(math.log(k/i)/math.log(2)))
            ans += 0.5**num/n
        else:
            ans += 1/n

    print(ans)

solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=[int(x) for x in input().split()]
bunshi=0
for i in range(1,min(k-1,n)+1):
    for j in range(20):
        if i*2**j>=k:
            bunshi+=2**(20-j)
            break
print("{0:.10f}".format(max(0,(n-k+1)/n)+bunshi/(n*2**20)))

Submission status: Accepted

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

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

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
    if i>k-1:
        ans+=tmp
    else:
        while i*2<k:
            i*=2
            tmp/=2
        ans+=tmp/2
print(ans)

Submission status: Accepted

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

prob = 0

s = 1
while N*s<K:
    s*=2

t = 0
for i in range(N,0,-1):
    if i*s>=K:
        t+=1
    else:
        s*=2
        t=t*2+1
        
print('{:.10f}'.format(t/s/N))

Submission status: Accepted

Solution code:
# coding: utf-8
import numpy as np
from functools import lru_cache
import time,math

def main(): 
    if True:
        N,K = list(map(int, input().split()))
    else:
        N = 10**5
        K = 10**5
        N = 3
        K = 10


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


    print(sum)
if __name__ =='__main__':
    main()

Submission status: Accepted

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

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

print('{:<20.16}'.format(p))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
  s=0
  while i<K:
    i*=2
    s+=1
  ans+=(1/N)*(1/(2**s))
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(20):
    if i * (2 ** j) >= k:
      win = j
      break
  ans += (1/2) ** win
print(float(ans/n))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
total = 0.0
for n in range(1, N+1):
    a = 0
    while True:
        if n*(2**a) >= K:
            total += 1/(N*(2**a))
            break
        a += 1

print(total)

Submission status: Accepted

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

    p += (N-K+1)/N
        
print(p)

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

N, K = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0

# 10^5
for i in range(1, N+1):
    # iはサイコロの出目
    cnt = 0
    score = i
    while(True):
        if score >= K:
            break
        score = score * 2
        cnt += 1
        
    ans += (1/N) * ((1/2) ** cnt)

print(ans)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

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

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

print(pro)

Submission status: Accepted

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

p = 0
for i in range(1, N + 1):
    if i >= K:
        p += (N - K + 1) / N
        break
    j = i
    p_ = 1
    while j < K:
        j *= 2
        p_ /= 2
    p += p_ / N

print(p)

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())
print(sum(
        map(lambda i: 0.5 ** (math.ceil(math.log2(k/i))) if i < k else 1, list(range(1, n+1)))
) / n)

Submission status: Accepted

Solution code:
import sys

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

res = 0

for i in range(1, N+1):
    if i >= K:
        res += 1 / N
        continue

    p = 1
    while i < K:
        i *= 2
        p *= 0.5
    res += (1 / N) * p

print(res)

Submission status: Accepted

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

sho=k*2
slist=[]

while sho>=1:
    sho=sho/2
    slist.insert(0, sho)

#print(slist)
nagasa=len(slist)
kaisulist=[]
now=0

for i in range(n):
    switch=0
    while switch==0:
        if now>=nagasa:
            switch=1
        elif i+1>=slist[now]:
            now+=1
        else:
            switch=1
    kaisulist.append(nagasa-now)
#print(kaisulist)

answer=0

for kl in kaisulist:
    answer+=(0.5**kl)

answer=answer/n
print(answer)

Submission status: Accepted

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

ans = 0
for i in range(1, N+1):
    tmp = float(1/N)
    now = i
    if now <= K-1:
        for k in range(100):
            now *= 2
            tmp *= float(1/2)
            if now >= K:
                break
    ans += tmp
print(ans)

Submission status: Accepted

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

ans = 0.0
for i in range(1, N + 1):
    point = i
    prob = 1.0 / N
    while point < K:
        point *= 2
        prob *= 0.5
    ans += prob

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# neccesary count
def ncount(k):
    count = 0
    cur = k
    while cur < K:
        cur <<= 1
        count += 1
    return count

print(sum(0.5 ** ncount(n) for n in range(1, N+1)) / N)

Submission status: Accepted

Solution code:
import math

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

for i in range(1, N+1):
    ans.append(math.ceil(math.log(max(1, K/i), 2)))

ans2 = 0

for i in ans:
    ans2 += 1 / 2**i / N

print(ans2)

Submission status: Accepted

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

def f(i,k,n):
     if i<k:
          m = math.ceil(math.log2(k/i))
          return ((1/2)**m)/n
     else:
          return 1/n

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

print(ans)

Submission status: Accepted

Solution code:
from math import ceil,log2
N,K=[int(a) for a in input().split()]
b=0.0
for n in range(1,N+1):
    if n<K:
        a=ceil(log2(K/n))
        b+=pow(2,-a)
    else:
        b+=1
print(b/N)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 21:04:18 2019

@author: Yamazaki Kenichi
"""

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

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,K=MAP()

cnt=[0]*N
for i in range(1, N+1):
    j=i
    while j<K:
        j*=2
        cnt[i-1]+=1

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

Submission status: Accepted

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

print(sum(ans))

Submission status: Accepted

Solution code:
def count_i(i, k):
    sum_num = i
    counter = 0
    while k > sum_num:
        sum_num *= 2
        counter += 1
    return counter


def main():
    n, k = [int(e) for e in input().split()]
    prob_sum = 0
    for i in range(1, n+1):
        prob = 1 / n * (1 / 2) ** count_i(i, k)
        prob_sum += prob
    print(prob_sum)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

total = 0 
for i in range(1,N+1):
    n = math.ceil(math.log2(K/i))
    if n > 0:
        total += 0.5**n
    else:
        total += N+1- i
        break
   

print(total/N)

Submission status: Accepted

Solution code:
a, b = map(int,input().split())
c = 1 / a
l = []
for i in range(1,a+1):
  count = 0
  d = i
  while d < b:
    d = d*2
    count += 1
  num = c * (0.5**count)
  l.append(num)
print(sum(l))

Submission status: Accepted

Solution code:
import random
import math

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

def frontCounter(n, k):
	count = 0
	if n >= k:
		return count
	current = n
	while True:
		count += 1
		current = current * 2
		if current >= k:
			return count

probe = 0
for n in range(1, N + 1):
	probe += (1 / N) * math.pow(0.5, frontCounter(n, K))
print(probe)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

print(ans/N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
X = [0]*(n+1)
import math as ma
ans = 0
for i in range(1,n+1):
    temp = ma.ceil(ma.log2(k/i)) if k >  i else 0 
    ans += (1/n)*(0.5**temp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
a,b=map(int,input().split())
ans=0.0
for i in range(1,a+1):
    # print(i,round(b/i,2),math.log2(i),math.log2(b/i),math.ceil(math.log2(b/i)))
    # print(i,(1 / ((2**(max(1,math.ceil(math.log2(b/i)))))*a)))
    temp = (1 / ((2**(max(1,math.ceil(math.log2(b/i)))))*a))
    if i >= b:
        temp = 1/a
    ans += temp
print(ans)

Submission status: Accepted

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

coin_num = [0]*(max(N,K)+1) 

cursor = K
count = 0
for i in range(len(coin_num)-1,0,-1):
    if i>=cursor:
        coin_num[i] = count
    else:
        while(i<cursor):
            cursor = (cursor+1)//2 
            count += 1
        coin_num[i] = count
        
ans = 0 
for i in range(1,N+1):
    ans += (1/N)*((1/2)**coin_num[i]) 
    
print(ans)

Submission status: Accepted

Solution code:
import math

# 入力n以上の最小の2のべきを出力
# 2**(out-1) < (in) <= 2**(out)
# power2_larger(8) = 3
# power2_larger(9) = 4
def power2_larger(num):
        return len(str(bin(num-1))[2:])


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

ans = 0.
for i in range(N):
  if (i+1) >= K:
    ans += 1.0 / N
  else:
    var = int((K + i) / (i+1))
    var2 = power2_larger(var)
    ans += 1.0 / N / 2**var2
    
print(ans)

Submission status: Accepted

Solution code:
from math import *

n,k=map(int,input().split())
s=0
for i in range(1,n+1):
    x=ceil(log2(k/i))
    if x<0:
        s+=n-i+1
        break
    s+=0.5**x
print(s/n)

Submission status: Accepted

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

ans=0
base=1

for n in range(1,N+1):
    base=1
    while(n*base<K):
        base*=2
    ans+=1/(base*N)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
def calc(n, k):
    prob = 0
    for i in range(1, n+1):
        #print(i)
        if i<k:
            time_to_win = int(np.ceil(np.log2(k/i)))
            prob += (1 / n) * (0.5**time_to_win)
        else:
            prob += (1/n) * (n- i+1)
            break
    return prob

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(prob)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

n,k = m()

a = 1/n

su = 0
nn = 0
for i in range(1,n+1):
	kk = -(-k//i)
	n = 1
	while True:
		if kk <= n:
			break
		else:
			n = n * 2
			nn += 1
	su += a * ((1/2) ** nn)
	nn = 0

print(su)

Submission status: Accepted

Solution code:
import math

N, K = [int(s) for s in input().split(" ")]
p = 0
for n in range(1, N+1):
    if n >= K:
        p += 1/N
    else:
        p += 1/N * (0.5 ** (math.ceil(math.log2(K/n))))
print(p)

Submission status: Accepted

Solution code:
import sys
from math import *
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

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

s = 0
for i in range(1,n+1):
    s += pow(1/2,calc(i,k))
print((1/n) * s)

Submission status: Accepted

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

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

Submission status: Accepted

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

mi = lambda: map(int, input().split())

N, K = mi()

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

print(ans/N)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc126/tasks/abc126_c
import itertools
from collections import Counter
from collections import defaultdict
import bisect
import math

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

    ans = 0.0
    if N < K:
        for i in range(1, N + 1):
            x = math.ceil(math.log2(K / i))
            # print(x)
            ans += (1 / min(N, K)) * 0.5 ** x
    else:
        ans += (N - K + 1) / N
        for i in range(1, K):
            x = math.ceil(math.log2(K / i))
            # print(x)
            ans += (1 / N) * 0.5 ** x

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


def solve(N: int, K: int):
    k = K
    power2 = 1
    n = N
    total = 0
    while k > 0:
        if n < k:
            k = int(math.ceil(k / 2))
            power2 *= 0.5
            continue
        total += (n - k + 1) * power2
        n = k - 1
        power2 *= 0.5
        if k == 1:
            break
        k = int(math.ceil(k / 2))
    print(total / N)
    return


# Generated by 1.1.4 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:
# -*- coding: utf-8 -*-
n,k = map(int, input().split())

bp = []
for i in range(30):
    bp.append(1/2**i)

res = 0
for i in range(1,n+1):
    if i>=k:
        res += 1/n
        continue
    x = i
    cnt = 0
    while x<k:
        x *= 2
        cnt += 1
    res += bp[cnt]/n

print("{:.12f}".format(res))

Submission status: Accepted

Solution code:
def task_c():
    n, k = map(int, input().split())
    from math import log2, ceil
    c = 0
    for i in range(1, n+1):
        if i >= k:
            c += 1/n
        else:
            c += 1/n * pow(0.5, ceil(log2(k / i)))
    print(c)
task_c()

Submission status: Accepted

Solution code:
from math import log2, ceil

n, k = [int(i) for i in input().split()]
ans = 0

for i in range(1, n + 1):
    if i >= k:
        ans += 1
        continue
    ans += 2 ** -ceil(log2(k / i))

print(ans / n)

Submission status: Accepted

Solution code:
import math

def main():
    buf = input()
    buflist = list(buf.split())
    N = int(buflist[0])
    K = int(buflist[1])
    divisor = N
    dividend = 0
    for i in range(N):
        dividend += 2 ** min(0, math.floor(math.log2(i+1) - math.log2(K)))
    print(dividend / divisor)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def func(i,K):
    od=0
    while(i*2**od<K):
        od+=1
    return 1/2**od

N,K=[int(x) for x in input().split()]
ans=0
od=0
#while(1):
#    if K//2**od==0:
#        break
#    if K//2**(od+1)>N:
#        cnt=0
#    elif K//2**od > N and K//2**(od+1)<=N:
#        cnt=N-K//2**(od+1)
#    else:
#        cnt=K//2**od-K//2**(od+1)
#    print(od,cnt)
#    ans=cnt*1/2**od*1/N
#    od+=1
#print (ans)
A = [0 for i in range(N+1)]
for i in range(1,N+1):
    A[i]=func(i,K)
print (sum(A)/N)

Submission status: Accepted

Solution code:
import math

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

K2 = math.log2(K)

out = sum([ (0.5) ** int(math.ceil(K2 - math.log2(me))) if me < K else 1 for me in range(1, N+1)]) / N

print(out)

Submission status: Accepted

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

ans = 0
cout = 0
while True:
  if N - K >= 0:
    ans += (N-K+1) / (2**cout)
    N = K - 1
  if K == 1:
    break
  K = (K+1) // 2
  cout += 1
print(ans / N_)

Submission status: Accepted

Solution code:
import bisect
import math
def solve():
  n,k = (int(i) for i in input().split())
  bairitu = [1]
  for i in range(1,20):
    bairitu.append(2*bairitu[i-1])
  ans = 0
  kakuritu = 1/n
  for i in range(1,n+1):
    if i >= k:
      ans += kakuritu
    else:
      rest = math.ceil(k/i)
      place = bisect.bisect_left(bairitu,rest)
      ans += kakuritu *((1/2)**place)
  print(ans)
  
solve()

Submission status: Accepted

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

for n in range(1,min(K,N+1)):
    ans += 2**(20-math.ceil(math.log2(K/n)))

ans /= 2**20

ans += max(N-K+1,0)
ans /= N

print(ans)

Submission status: Accepted

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

ratio = 0
for i in range(N):
    dice = i+1
    tmp = dice
    tmp_ratio = 1.0 / N
        
    while(tmp < K):
        tmp = tmp * 2
        tmp_ratio *= 0.5
    ratio += tmp_ratio

print(ratio)