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:
#ABC126_C
N,K=map(int,input().split())
ans=0

def bichk(n,K):
    #nに2の何乗を書けたらKを超えるか＝nに何回２をかけたらKを超えるか
    a=0
    while 1:
        if n*(2**a)>=K:
            return(a)
            break
        a+=1
if N<K:
    for i in range(1,N+1):
        ans+=(1/N)*(0.5**bichk(i,K))
else:
    ans+=(N-K+1)/N
    for i in range(1,K):
        ans+=(1/N)*(0.5**bichk(i,K))
print(ans)

Submission status: Accepted

Solution code:
def kakuritu(N, n, K):
    t = 1
    count = 0
    while N * t < K:
        t = t * 2
        count += 1
    return count

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

n = 1
kt = 0
for i in range(1,N+1):
    kt += (1 / N) * ((1/2)**kakuritu(i, n, K))
    n += 1

print(kt)

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)
        continue
    X = int(math.log((K/i), 2))
    if (K/i) % 2**X == 0:
        pass
    else:
        X += 1
    ans += (1/N) * (1/2) ** X
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
sum = 0
for i in range(1,n+1):
    for j in range(20):
        if i * (2 ** j) >= k:
            count = j
            break
    sum += 1 / ((2 ** j) * n)
print(sum)

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
    for j in range(18):
        if i*2**j>=k:
            ans+=(1/n)*(1/2)**j
            break
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
x=1/n
y=1/2
ans=0
for i in range(1,n+1):
    if i>=k:
        ans+=x
        continue
    for j in range(18):
        if i*2**j>=k:
            ans+=x*y**j
            break
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
x=1/n
y=1/2
ans=0
for i in range(1,n+1):
    for j in range(18):
        if i*2**j>=k:
            ans+=x*y**j
            break
print(ans)

Submission status: Accepted

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

ans = 0
cnt = 0

for n in range(1, N+1):
    c = 0
    while True:
        total = n * 2 ** c
        if total >= K:
            ans += 0.5 ** c / N
            break
        c += 1

print(ans)

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
prob = []
for i in range(N):
  if i+1 >= K:
    prob.append(1)
  else:
    temp = i+1
    x = 0
    while temp < K:
      temp *=2
      x += 1
    prob.append(0.5**x)
Answer = sum(prob)/N

print(Answer)

Submission status: Accepted

Solution code:
import math

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

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

print(p)

Submission status: Accepted

Solution code:
from math import log2
from math import ceil
n,k=map(int,input().split())
p=0


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

print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

t = []

if K > N:
  max = N
  for i in range(max):
    t.append(math.ceil((math.log10(K) - math.log10(i+1))/math.log10(2)))
else:
  max = K
  for i in range(max):
    t.append(math.ceil((math.log10(K) - math.log10(i+1))/math.log10(2)))
  for i in range(N - K):
    t.append(0)

Answer_n = 0
for item in t:
  Answer_n += 0.5**item

Answer = Answer_n / N

print(Answer)

Submission status: Accepted

Solution code:
import math

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


prob = 0
for m in range(1, n + 1):
    if m >= k:
        prob += 1 / n
    else:
        p = math.ceil(math.log(k / m) / math.log(2))
        prob += (1 / n) / (2 ** p)

print(prob)

Submission status: Accepted

Solution code:
import math


n, k = [int(i) for i in input().split()]
prob = 0
for i in range(1, n + 1):
    if i >= k:
        exp = 0
    else:
        exp = math.ceil(math.log2(k) - math.log2(i))
    prob += (1 / n) * (1 / 2) ** exp
print(prob)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
cnt=0
A=[0]*(N)

for i in range(N):
  cnt=0
  p=i+1
  for j in range(17):
    if p<K:
      p*=2
      cnt+=1
      if p>=K:
        A[i]=cnt
        break

ans=0
for i in A:
    ans+=(1/N)*((0.5)**i)
    
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):
    if i < K:
        T = math.ceil(math.log(K / i,2))
    else:
        T = 0
    total += 1 / (N * 2 ** T)
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

import math


sum_prob=0

for i in range(1,N+1):
    ratio =  K / i


    power = math.ceil(math.log2(ratio))
    if power <= 0:
        sum_prob+=1/N
        continue
    sum_prob += (1/(2**power ))/ N


print(sum_prob)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

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

ans = 0
if N >= K:
    ans += (N-K+1)/N
    M = K-1
else:
    M = N
cnt = 1

while K>1:
    K = math.ceil(K/2)
    if K <= M:
        ans += (M-K+1)/((2**cnt)*N)
        M = K-1
        cnt += 1
    else:
        cnt += 1

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
tmp = 0
for x in range(1, N + 1):
    a = 0
    n = 0
    while K > x:
        x *= 2
        n += 1
    p = 1 / N * (1 / 2 ** n)
    tmp += p
print(tmp)

Submission status: Accepted

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

w = n - k + 1

if n < k:
    l = n
else:
    l = k - 1

C = []
for i in range(1, l + 1):
    c = 0
    while i < k:
        i *= 2
        c += 1
    C.append(c)

ans = 0
for c in C:
    ans += (1 / n) * (1 / 2)**c
if w > 0:
    ans += w / n

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0	
for i in range(1,n+1): #出る目[1,n]について調べる
	l=0
	while i*2**l<k:
		l+=1
	ans+=1/n*(1/2)**l
print('{:.10f}'.format(ans)) #小数点以下8桁表示

Submission status: Accepted

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

two = 0
for i in range(1, n+1):
    two_count =0
    score = i
    while score <= k-1:
        score *= 2
        two_count += 1

    two += (1/2) ** two_count

print((1/n) * two)

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-1:
        tmp *= 2
        cnt += 1
    ans += 1/(2**cnt)

ans /= n

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ret)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

def bunbo(N):
    return 1/N

def n_calc(n, K):
    A = math.log10(K/n)/math.log10(2)
    A = A + 0.9999999999
    A = int(A)
    return A

def calc(N, K):
    result = 0
    const = 1/N
    for i in range(1, N+1):
      c = n_calc(i, K)
      if c < 0:
        c = 0
      result += (const * ((1/2)**c))
    return result
  
print(calc(N, K))

Submission status: Accepted

Solution code:
from math import log2, ceil
N, K = map(int, input().split())
print("{:.12f}".format(sum(min(1, 1/2**ceil(log2(K/i))) for i in range(1, N+1))/N))

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
  
  else:
    m = math.ceil(math.log2(K/n))
    ans += (1/N)*(0.5**m)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
ans = []
for i in range(1, n+1):
    wins = 0
    score = i
    while True:
        if score >= k:
            break
        score *= 2
        wins += 1
    ans.append(pow(0.5, wins))
print(sum(ans)/len(ans))

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC-126-C
N, K = map(int, input().split())
possibility = 0

def check_double(n, K):
    count = 0
    while n < K:
        n *= 2
        count += 1
    return count

for i in range(1, N+1):
    possibility += (1/N) * (0.5 ** check_double(i, K))

print(possibility)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,K = [int(i) for i in input().split()]
P = 0
score = 0
count = 0
for n in range(1,N+1) :
    score = n
    while score < K :
        score*=2
        count+=1
    P += (1/N) * (1/2) ** count
    score = 0
    count = 0
print(P)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc126/tasks/abc126_c
N, K = list(map(int, input().split()))

probs = []
keisuu = 1 / N
for dice in range(1, N + 1):
    score = dice
    cnt = 0
    while score < K:
        score *= 2
        cnt += 1
    probs.append(keisuu * (1 / 2)**cnt)


print(sum(probs))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

per  =  0
for i in range(1, N+1):
  omote = max(int(math.ceil(math.log2(K/i))), 0)
  per += (1 / N) * (0.5 ** omote)
  #print(omote)
print(per)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(1,n + 1):
    double = i
    for j in range(1000):
        if double >= k:
            break
        else:
            double = double << 1
    ans += (1 / n) * ((1 / 2)**j)

print(ans)

Submission status: Accepted

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

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

print(exp / 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*pow(2,cnt) < k:
        cnt += 1
    ans += ((1/2)**cnt)/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
    coin = 0
    while score < k:
        score *= 2
        coin += 1
    ans += 1/n * 0.5 ** coin

print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
tmp = K/N
q = 1
p = 2 ** 20
while p/q >2:
    qp = q*2
    if qp > tmp:
        p = qp
    else:
        q = qp
res = 0
for i in range(N,0,-1):
    ans = i*q
    if ans < K:
        q*=2
    res+= float(1)/q
print(res/N)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
tmp = K/N
q = 1
p = 2 ** 100
while p/q >2:
    qp = q*2
    if qp > tmp:
        p = qp
    else:
        q = qp
res = 0
for i in range(N,0,-1):
    ans = i*q
    if ans < K:
        q*=2
    res+= float(1)/q
print(res/N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = []
M = 10000
h = 1
l.append(h)
while h < M:
    h*=2
    l.append(h)
# print(l)
N,K = map(int,input().split())
ans = 1
res = 0
for i in range(N):
    ans = i + 1
    tmp = 1
    aro = 1
    while ans < K:
        ans *= 2
        tmp = 0.5**aro
        aro += 1
#     print(aro)
    res += tmp
print(res/N)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,k = LI()

ans = 0
for i in range(1,n+1):
    tmp = i
    x = 1/n
    while tmp < k:
        tmp *= 2
        x *= 0.5
    ans += x
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
    else:
        j = math.ceil(math.log2(k/i))
        ans += (1/2)**j
print(ans/n)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
m = min(N, K)
n = N - m
p = n
for i in range(m):
  k = 1
  while K > (i + 1) * k:
    k *= 2
  p += 1 / k
print(p / N)

Submission status: Accepted

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

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

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-1:
        ans += (0.5)**math.ceil(math.log2(K/i)) /N
    else:
        ans += 1/N

print(ans)

Submission status: Accepted

Solution code:
N,K = list(map(int, input().split()))
win = 0
#全事象に対して
for i in range(N):
    #確率
    j = 1
    k = j + i
    #現在のスコア<目的スコアになるまで
    while k < K:
        #コイントスごとに確率は1/2になる
        j /= 2
        #現在のスコアは2倍になる
        k *= 2
    #while文を通らなかったものは１が足される
    win += j
print(win/N)

Submission status: Accepted

Solution code:
#126-C
n,k=map(int,input().split())
pro=0

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

Submission status: Accepted

Solution code:
def main():
	n,k = map(int,input().split())
	ans = 0
	for i in range(n):
		su = i+1
		count = 0
		# print("su= {}".format(su))
		# print("i = {}".format(i))
		while su < k:
			su *= 2
			count += 1
			# print(su)
		# print("count = {}".format(count))
		ans += (1/n)*(0.5)**count
		# print("ans = {}".format(ans))
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

win = 0
for i in range(N):
    j = 1
    k = j + i
    while k < K:
        j /= 2
        k *= 2
    win += j
print(win/N)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
for i in range(1, n+1) :
  for j in range(k+1) :
    if i*(2**j) >= k :
      ans += (1/n) * ((1/2)**j)
      break
  else:
    print('error')

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(k+1) :
    if i*(2**j) >= k :
      ans += (1/n) * ((1/2)**j)
      break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

n = 0

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

print(ans)

Submission status: Accepted

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

ans = 0

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

for i in range(1, min(N+1, K)):
    p = math.ceil(math.log2(K/i))
    ans += math.pow(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):
	score=i
	p=1
	while(score<k):
		score*=2
		p/=2
	ans+=p
print(ans/n)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
import math
if K > N:
  a = sum([2 ** -(math.ceil(math.log2(K/i))) for i in range(1,N+1)])
  a = a / N
  print(a)
else:
  a = sum([2 ** -(math.ceil(math.log2(K/i))) for i in range(1,K)])
  a = a /N + (N-K+1)/N
  print(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
rate = 0
for i in range(1, n + 1):
  count = 0
  while True:
    if i * (2 ** count) >= k:
      break
    count += 1
  rate = rate + ((1 / n) * (1 / (2**count)))

print(rate)

Submission status: Accepted

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

import math
ans=0
for m in range(1,n+1):
    if m>=k:
        l=0
    else:
        l=math.ceil( math.log(k/m,2) )
    ans+=(0.50)**l /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):
  p = 1 / n
  now = i
  while now < k:
    now *= 2
    p /= 2
  ans += p
print(ans)

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())
ans = 0
if n >= k: ans += n - k + 1
p = 1/2
while k > 1:
  if n >= k: ans += p * (k - math.ceil(k / 2))
  elif n >= k / 2: ans += p * (n - math.ceil(k / 2) + 1)
  k = math.ceil(k / 2)
  p /= 2
print(ans / n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
point = 0
count = 0
for i in range(1, n + 1):
    point = i
    while (not (point >= k)):
        point *= 2
        count += 1
    ans += (1 / n) * (1 / 2)**count
    point = 0
    count = 0
print("{:.9f}".format(ans))

Submission status: Accepted

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

pro_won = list()

for i in range(1, N+1):
    u = i
    z = 0
    cnt = 0
    if K <= u:
        z = 1/N
        pro_won.append(z)
    else:
        while u < K:
            u = 2*u
            cnt +=1
        z = (0.5**cnt)/N
        pro_won.append(z)
print(sum(pro_won))

Submission status: Accepted

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

ret = 0.0
for i in range(1, N + 1):
    # サイコロの点数がi, 確率が 1/N
    tmp = 1.0 / N
    # コインを振る
    now = i
    while now < K:
        # 点数以下ならばサイコロを振る
        now *= 2  # 点数は倍
        tmp /= 2  # 確率は1/2
    ret += tmp
    
print("{:.12f}".format(ret))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,k = list(map(int,input().split()))

from decimal import Decimal
k = Decimal(k)
n_list = [Decimal(i) for i in range(n,0,-1)]
coin_cnt_list = [0] * n
cur_coin_cnt = 0
cur_pow_coin_cnt = 1

for i,v in enumerate(n_list):
    while v * cur_pow_coin_cnt < k:
        cur_coin_cnt+=1
        cur_pow_coin_cnt*=2
    coin_cnt_list[i]=cur_coin_cnt

from collections import defaultdict
d = defaultdict(int)

for key in coin_cnt_list:
    d[key] += 1

ret = Decimal(0)
for k,v in d.items():
    ret += 1/Decimal(2**k) * Decimal(v)
ret /= Decimal(n)
print(ret)

Submission status: Accepted

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

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

    ans += (1/n)*(1/2)**cnt
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, n + 1):
    num = 1

    while i * num < k:
        num *= 2
    ans += 1 / num
print(ans / n)

Submission status: Accepted

Solution code:
import math


def main():
    N, K = map(int, input().split())
    accum = 0
    for i in range(1, len(bin(K)) - 2 + 1):
        cur = max(0, N - (math.ceil(K * 0.5 ** i)) + 1) * 0.5 ** i
        pre = max(0, N - (math.ceil(K * 0.5 ** (i - 1))) + 1) * 0.5 ** i
        accum += cur - pre
    print((max(0, N - K + 1) + accum) / N)
    return


main()

Submission status: Accepted

Solution code:
import math


def main():
    N, K = map(int, input().split())
    print((max(0, N - K + 1) + sum(
        max(0, N - (math.ceil(K * 0.5 ** i)) + 1) * 0.5 ** i
        - max(0, N - (math.ceil(K * 0.5 ** (i - 1))) + 1) * 0.5 ** i
        for i in range(1, len(bin(K)) - 2 + 1))) / N)
    return


main()

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

Submission status: Accepted

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

Sum = 0

for i in range(1,N+1):

    j = 0

    while (2 ** j) * i < K:
        j += 1
    i -= 1
    Sum += 1/(2 ** j)
    

print(Sum / N)

Submission status: Accepted

Solution code:
def double(i, k):
    cnt = 0
    while True:
        if i >= k:
            break
        i *= 2
        cnt += 1
    return cnt


def main():
    N, K = map(int, input().split())
    ans = 0
    for i in range(1, N+1):
        ans += 1/N * (0.5**double(i, K))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


def main():
    N, K = map(int, input().split())
    print((max(0, N - K + 1) + sum(
        max(0, N - (math.ceil(K * (1 / 2) ** i)) + 1) * (1 / 2) ** i
        - max(0, N - (math.ceil(K * (1 / 2) ** (i - 1))) + 1) * (1 / 2) ** i
        for i in range(1, len(bin(K)) - 2 + 1))) / N)
    return


main()

Submission status: Accepted

Solution code:
import math


def main():
    N, K = map(int, input().split())
    print((max(0, N - K + 1) + sum(
        max(0, N - (math.ceil(K * (1 / 2) ** i)) + 1) * (1 / 2) ** i
        - max(0, N - (math.ceil(K * (1 / 2) ** (i - 1))) + 1) * (1 / 2) ** i
        for i in range(1, len(bin(K)) - 2 + 1 + 1))) / N)
    return


main()

Submission status: Accepted

Solution code:
import sys
import math
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, K = MAP()

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

Submission status: Accepted

Solution code:
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 += 1/n * (1/2)**j
            break

print(ans)

Submission status: Accepted

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

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 += 1 / (n * (2 ** j))
            break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum(p)/n)

Submission status: Accepted

Solution code:
import math
def main():
    N, K = map(int, input().split())
    l = [0] * (math.ceil(math.log2(K)) + 1)
    t = 2
    for i in range(len(l)):
        l[i] = t * 1/2
        t = l[i]
    p = 0
    for i in range(1, min(K, N+1)):
        p += l[math.ceil(math.log2(K/i))]
    p += max(N-K + 1, 0)
    p /= N
    return p

print(main())

Submission status: Accepted

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

half = k / 2
while True:
  half_list.append(half)
  half = half / 2
  if half < 0.5:
    break

half_list.reverse()
# print(half_list)
ans = 0

for i in range(1, n+1):
  # i が出る確率
  i_prob = 1 / n
  # k を超えるまでに連続して表を出す回数
  half_i = 0
  for j in range(len(half_list)):
    if i >= half_list[j]:
      half_i = j
    else:
      break
  omote_count = len(half_list) - (half_i + 1)
  # print(omote_count, half_i)
  ans += i_prob * ((1 / 2) ** omote_count)
  

print(round(ans, 12))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
prob = 0
for init in range(1, n+1):
  for i in range(10000000):
    point = init * 2**i
    if point >= k:
      p = 0.5**i    
      break
  prob += p
print(prob / n)

Submission status: Accepted

Solution code:
from math import log2,ceil
n,k=map(int,input().split())
p=0
for i in range(1,n+1):
  if i<k:
    p+=0.5**(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):
  cnt = 0
  x = i
  while x <= k-1:
    x = x * 2
    cnt += 1
  ans += 1 / (2**cnt)
  
print("{0:.12f}".format(ans/n))