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())

g = 0
ps = 0
for i in range(n):
    g = i+1
    m = 0
    while g < k:
        g = g * 2
        m = m + 1
    p = float(0.5**m / n)
    ps = ps + p

print(ps)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

def f(n):
	global K
	x = math.ceil(math.log(K/n, 2))
	if x < 0:
		x = 0
	if x > K:
		x = K
	return (0.5)**x

print('{:.10f}'.format(sum([f(n) for n in range(1, N+1)])/N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

def prob(a, n, k):
    c = math.ceil(math.log(k/a,2))
    return (1/n)*(1/2)**c

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

for i in range(1,min(N,K)+1):
    ans += prob(i, N, K)

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
c=[i for i in range(1,n+1)]
ans=0

def ta(m,cnt):
    if k>m:
        cnt+=1
        m*=2
        return ta(m,cnt)
    else:
        return cnt

for i in c:
    cnt=0
    x=(0.5**ta(i,cnt))/n
    ans+=x
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int, input().rstrip().split())
pro = 0.
for i in range(1,N+1):
    x = np.log2(K) - np.log2(i)
    x = np.ceil(x)
    if x > 0:
        pro += 1/N*(1/2)**x
    else:
        pro += 1/N
print(pro)

Submission status: Accepted

Solution code:
#Kに対して何回コインを投げればよいのか
N, K = map(int, input().split())
each_slow = []
for i in range(1, N+1): #diceの目が1～3の目の間
    d = i
    cnt = 0
    while (d<K):
        cnt += 1
        d *= 2
    each_slow.append(cnt)

#各サイコロの目に対する勝率の算出
dice = 1/N #サイコロの目が出る確率
coin = 1/2 #コインの表が出る確率

win = [] #各勝率を格納するリスト
for i in range(1, N+1):
    #確率算出
    rate = dice * coin ** each_slow[i-1]
    win.append(rate)
    
print(sum(win))

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

Submission status: Accepted

Solution code:
# C - Dice and Coin
n, k = list(map(int, input().split()))
prob = 0

for i in range(1, n+1):
    if i >= k:
        prob += 1/n
    else:
        m = 1
        while i*2**m < k:
            m += 1
        prob += 1/n * (0.5) ** m
        
print(prob)

Submission status: Accepted

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

for n in range(1,N+1):
    count = 0
    if n < K:
      while n < K:
        n *= 2
        count += 1
    tmp += (1/N) * (1/2)**count
print(tmp)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())

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

print(ans / N)

Submission status: Accepted

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

Submission status: Accepted

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

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):
    percent = (1 / 2)**ceil(log(ceil(K / i), 2))
    ans += percent
print(ans/N)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = []
for i in range(1,n+1):
    if i < k:
        tmp = k/i
        counter = 0
        for _ in range(1000000):
            tmp = tmp/2
            if tmp <=1:
                break
            else:
                counter +=1
        ans.append(1/n*(1/2)**(counter+1))
    else:
        ans.append(1/n)
print(sum(ans))

Submission status: Accepted

Solution code:
import numpy as np
 
N, K = map(int, input().split())
 
def get_x(n, K):
    if n >= K:
        return 0
    else:
        x_raw = np.log2(K) - np.log2(n)
        return np.ceil(x_raw)

def get_prob(n, K):
    x = get_x(n, K)
    if x == 0:
        return 1
    else:
        return (1/2)**x
    
ans = np.mean([get_prob(n, K) for n in range(1, N+1)])
 
print(ans)

Submission status: Accepted

Solution code:
# ABC126C - Dice and Coin
n, k = list(map(int, input().rstrip().split()))
ans = 0
for i in range(1, n + 1):
    if i >= k:
        ans += 1 / n
    else:
        m = 1
        while i * 2 ** m < k:
            m += 1
        ans += 1 / n * (0.5) ** m
print(ans)

Submission status: Accepted

Solution code:
import sys

def prob(cur, t):
    if cur >= t: return 1
    return 1.0/2.0 * prob(2*cur, t)

if __name__ == '__main__':
    input = sys.stdin.read()
    N, K = map(int, input.split())
    res = 0
    for i in xrange(1, N+1):
        res += 1.0/N * prob(i, K)
    print res

Submission status: Accepted

Solution code:
import numpy as np
import math

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


prob = []
if N >= K:
    p_e = (1 / N) * (N - K + 1)
    for i in range(1, K):
        p_i = (1 / N) * ((1 / 2) ** (math.ceil(np.log2(K / i))))
        prob.append(p_i)

else:
    p_e = 0
    for i in range(1, N+1):
        p_i = (1 / N) * ((1 / 2) ** (math.ceil(np.log2(K / i))))
        prob.append(p_i)


s = sum(prob) + p_e
print("{:.12f}".format(s))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from fractions import Fraction
N, K = map(int, input().split())
F = 0

for i in range(1, N + 1):
    point = i
    j = 0
    while point < K:
        point *= 2
        j += 1
    F += float((1/N) * ((1/2) ** j))

print(F)

Submission status: Accepted

Solution code:
import math
range2 = 17
tables = list(map(lambda x: 2.0 ** (range2-x), range(range2+1)))
 
line = input()
N , K = list(map(int, line.split(' ')))
result = 0
for i in range(N):
    dice = i + 1.0
    if dice >= K:
        result += tables[0]
        continue
    val = math.ceil(math.log2(K / dice))
    result += tables[val]
finalResult = result / N / (2**17)
print('{:.12f}'.format(finalResult))

Submission status: Accepted

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

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

print(ans/N)

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    ans = 0
    for n in range(1, N + 1):
        cnt = 0
        while n < K:
            n = n << 1
            cnt += 1
        ans += (1 / N) * (0.5**cnt)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans /= n

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f(x,y):
    i=1
    while x<y:
        x*=2
        i*=2
    return 1/i

n,k=map(int,input().split())
q=0
for i in range(1,n+1):
    q+=f(i,k)
print(q/n)

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    ans = 0
    for n in range(1, N + 1):
        s = n
        c = 0
        while K > s:
            s *= 2
            c += 1
        ans += (1 / N) * (1 / 2) ** c
    print(ans)


main()

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    ans = 0
    for n in range(1, N + 1):
        s = n
        c = 1
        while K > s:
            s *= 2
            c /= 2
        ans += (1 / N) * c
    print(ans)


main()

Submission status: Accepted

Solution code:
N,K = input().strip().split(' ')
N,K = [int(N),int(K)]

P = 0.0

for n in range(1,N+1) :
    count = 0
    k = n
    while k < K:
        count += 1
        k = k * 2
    
    P += ( 1 / N * 1/pow(2,count))
    # print(P)

print(P)

Submission status: Accepted

Solution code:
import math
a, b=map(int, input().split())
n=s=0
if b<=a:
	n=a-b+1
for i in range(1, min(a+1,b)):
	p=b/i
	p=math.ceil(math.log2(p))
	s+=(1/a)*(0.5**p)
print(s+(n/a))

Submission status: Accepted

Solution code:
import math

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

a = 0
b = 0
l = []
for i in range(18):
    if (2 ** i >= k / n):
        a = i
        break
for i in range(b, 18):
    if (2 ** i >= k):
        b = i
        break

l.append([a, n - math.ceil(k / (2 ** a)) + 1])
for i in range(a + 1, b + 1):
    c = math.ceil(k / (2 ** (i - 1))) - math.ceil(k / (2 ** i))
    l.append([i, c])

s = 0
for i in l:
    s += i[1] / (2 ** i[0])

print(s / n)

Submission status: Accepted

Solution code:
print("{0:.15f}".format((lambda n:sum([1/(1<<sum([1 if i*(1<<j)<n[1]else 0 for j in range(20)])) for i in range(1,n[0]+1)])/n[0])(list(map(int,input().split())))))

Submission status: Accepted

Solution code:
'''input
100000 5
'''
from math import ceil, log2
N, K = [int(x) for x in input().split()]

ats = 0.0

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

	ats += 1/N/(2.0**(float(ceil(log2(K/i)))))

print(ats)

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import math
N,K = [int(x) for x in input().split()]
ans = 0
a =[]
for i in range (1,N+1):
    n = math.ceil(math.log2(K/i))
    if n >= 0:
        ans += (1/N) *((1/2)**n)
    else:
        ans += 1/N
    a.append(n)






print(ans)

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif abs((math.log(K)-math.log(n))//math.log(2)-(math.log(K)-math.log(n))/math.log(2))<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x

print(cnt/N)

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
cnt2 = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif abs((math.log(K)-math.log(n))//math.log(2)-(math.log(K)-math.log(n))/math.log(2))<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt2 += (0.5)**x
  

print(cnt2/N)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
if n>=k:
    a=k-1
else:
    a=n
b=[1/n]*n
for i in range(1,a+1):
    j=i
    while i<k:
        b[j-1]=1/2*b[j-1]
        i=i*2
print(sum(b))

Submission status: Accepted

Solution code:
import math
import sys
import numpy

N,K = map(int, input().split())
a = 0.000000000
b = 1
for i in range(1,N+1):
    b = 1
    if i >= K:
        a += 1/N
    else :
        tmp = i
        while tmp < K:
            tmp *= 2
            b /= 2
        a += b/N
print(a)

Submission status: Accepted

Solution code:
import math

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

print(sum([pow(0.5, math.ceil(math.log2(K/a))) if math.log2(K/a) >= 0 else 1 for a in range(1, N+1)])/N)

Submission status: Accepted

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

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:
        val=1
        ab=i
        while(ab<k):
            ab*=2
            val*=2
        val*=n
        ans+=(1/val)
print(ans)

Submission status: Accepted

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

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
    else:
        p += (1/N) * (1/2) ** math.ceil(math.log(K / i, 2))

print(p)

Submission status: Accepted

Solution code:
import math
N,K = [int(x) for x in input().split()]
p = 0
for x in range(N):
    k = K/(x+1)
    if x < K:
        k_log = math.ceil(math.log2(k))
    else:
        k_log = 0
    p += 1/N/pow(2,k_log)

print(p)

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
    else:
        ans += 0.5 ** ceil(log(K / i, 2)) / N
print(ans)

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
cnt = 0
for n in range(1,N+1):
    x = 0
    while n*(2**x) < K:
        x += 1
    cnt += (0.5)**x

print(cnt/N)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def f(x, y):
    i = 1
    while i * x < y: i *= 2
    return 1 / i

n, k = map(int, input().split())
p = sum(f(i, k) for i in range(1, min(k, n + 1)))
print((max(0, n - k + 1) + p) / n)

Submission status: Accepted

Solution code:
import math

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

ans = 0
for i in range(1, n+1):
    ans += 1 / (2 ** int(math.log2((k-1)//i)+1 if (k-1)//i != 0 else 0))

print('{:.9}'.format(ans / n))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import math

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

#コインを何度投げるかの配列
l = []
#少し足して切り上げの手助け
ln = n+0.5**9
#コインを0回投げて勝てるパターン数を記録
l.append(math.ceil(ln-k) if ln-k>=0 else 0)
#コインを0回投げて勝てるパターン数を減らす
ln -= math.ceil(ln-k) if ln-k>=0 else 0

for _ in range(1,k+1):
    k/=2
    #コインをi回投げて勝てるパターン数を記録
    l.append(math.ceil(ln-k) if n-k>0 else 0)
    #コインをi回投げて勝てるパターン数を減らす
    ln-=math.ceil(ln-k) if n-k>0 else 0
    #kが1より下になった場合終了
    if k<=1:
        break
ans = 0
for i in range(len(l)):
    #インデックス番号文2で割って合計を出す
    ans += l[i]/n/2**i
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 解説を見ての実装
N, K = map(int, input().split())
ret = 0
for i in range(1, N+1):
    tmp = 1.0/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())

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

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
# import numpy as np

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

diceProb = 1/N
tmp = 0
tmpVal = 0
prevCnt = 0

for n in range(1,N+1):
	tmpVal = n
	cnt = 0
	while tmpVal < K:
		tmpVal *= 2
		cnt += 1

	if prevCnt != cnt:
		# print(cnt,n)
		prevCnt = cnt
	tmp += 2**(-cnt)


print("{:.12f}".format(tmp*diceProb))

Submission status: Accepted

Solution code:
n,g=map(int,input().split())
ans=0
basis=1/n
if g==1:
  print(1)
  exit()
  
A=[1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072]

for i in range(1,n+1):
  A.append(g/i)
  A.sort()
  k=A.index(g/i)
  ans+=basis*(0.5**k)
  del A[k]
print(ans)

Submission status: Accepted

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

for x in range(1, N+1):
    prob = 1
    while x < K:
        prob *= 0.5
        x *= 2
    result += prob/N

print('{0:.9f}'.format(result))

Submission status: Accepted

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

for i in range(1, N+1):
    prob = 1
    x = i
    for j in range(i, K):
        if K <= x:
            break
        prob *= 0.5
        x *= 2
    result += prob/N

print('{0:.12f}'.format(result))

Submission status: Accepted

Solution code:
from sys import stdin
n, k = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
 
n, k = map(int, input().split())
prob = 0
for i in range(1, n+1):
  count = 0
  total = i
  while total < k:
    total *= 2
    count += 1
  prob += 1/2**count
print(prob/n)

Submission status: Accepted

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

for i in range(1, N+1):
    prob = 1
    x = i
    while x < K:
        prob *= 0.5
        x *= 2
    result += prob/N

print('{0:.12f}'.format(result))

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc126/tasks/abc126_c
N, K = map(int, input().split())
ans = 0
for i in range(1, N+1):
    now = i
    p = 1
    while now < K:
        now *= 2
        p *= 1/2
    ans += p * 1/N  
print(ans)

Submission status: Accepted

Solution code:
#   C

import numpy as np

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

sum_poss = 0
for n in range(1, N+1):
    m = 0
    poss = 1
    while n*2**m < K:
        m += 1
        poss /= 2
    sum_poss += poss/N
    
#sum_poss /= N


print(sum_poss)

Submission status: Accepted

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


def tell_power_number(number):
    i = 0
    while number * (2 ** i) < K:
        i += 1
    return i


ans = 0
if N <= K - 1:
    for k in range(1, N + 1):
        ans += 1 / N * (1 / 2) ** tell_power_number(k)
else:
    for k in range(1, K):
        ans += 1 / N * (1 / 2) ** tell_power_number(k)
    ans += (N - K + 1) / N

print(ans)

Submission status: Accepted

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

t = []
d = k
while(True):
  d = d / 2
  t.append(d)
  if d <= 1:
    break
# print(t)

t2 = []
nn = 1+n if n < k else k
for i in range(1, nn):
  for j in range(len(t)):
    if i >= t[j]:
      t2.append(j+1)
      break
# print(t2)

t3 = [0.5]
for i in range(1, math.ceil(math.log(k, 2))):
  t3.append(t3[i-1]*0.5)
# print(t3)

r = 0
for t in t2:
  r += t3[t-1]
r /= n
if n >= k:
  r += (n-k+1) / n
print(r)

Submission status: Accepted

Solution code:
N,K = map( int, input().split())
#a = [0 for in range(K)]
l = [0]
if N>=K:
  l[0] = N-K+1
now = K-1
cnt = 2
while now>=1:
  nx = now // 2
  if N > now:
    a = now-nx
  elif now >= N > nx:
    a = N - nx
  else:
    a = 0
  l.append(a)
  now = nx
  cnt *= 2
#print( N, win, win/N )
#print(l)
ll = len(l)
pp = 1
for i in range(ll):
  l[ll-i-1] *= pp
  pp *= 2
#print(l)
suml = sum(l)
print( suml/(pp/2)/N)

Submission status: Accepted

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

import math
P = 0
if N < K:
    for i in range(1,N+1):
        P += ((0.5)**(math.ceil( math.log2(float(K/i)) )))/N
else:
    P += (N-K+1)/N 
    for i in range(1,K):
        P += ((0.5)**(math.ceil( math.log2(float(K/i)) )))/N
print(P)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ret = 0
for die in range(1, n + 1):
    cur = die
    p = 0
    while cur < k:
        cur <<= 1
        p += 1
    ret += 1 / n * (0.5 ** p)
print(ret)

Submission status: Accepted

Solution code:
import math

N, K = map(int,input().split())
#N, K = 100000, 5

ans = 0
total = 0
for i in range(0,N):
	if i < K:
	#dice_times = math.ceil(math.log2(K/(i+1)))
		dice_times = math.ceil(math.log2(K/(i+1)))
		total = total + (0.50000000000**dice_times)
		#print(total)
	else:
		total += 1

print(total/N)

Submission status: Accepted

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

P = 0

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

print(P/N)

Submission status: Accepted

Solution code:
import math

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

ans = float(0)

Kd = float(0)
Nd =int(0)
i = int(1)


if N>=K:
    Nd = K-1
    ans += N-K+1

else:
    Nd = N

while Nd>=1 :
    Kd = K/(2**i)
    if Kd<=Nd:
        ans += (Nd - math.ceil(Kd) +1) / (2 ** i)

        if math.ceil(Kd)-math.floor(Kd)==0.0:
            Nd = math.ceil(Kd)-1
        else: Nd = math.floor(Kd)

    i +=1


ans = ans/N

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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


N,K=spaceinput()

res=0

for i in range(1,N+1):
    if K>i:
        tmp=np.ceil(np.log2(K/i))
        res+=(0.5**tmp)/N
    else:
        res+=1/N

    


print(res)

Submission status: Accepted

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

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

print(P / N)

Submission status: Accepted

Solution code:
n, k = (int(i) for i in input().split())
 
def win_num(f, k):
    i = 0
    F = f
    while F<k:
        F = f
        F = F*(2**i)
        i += 1
    if i == 0:
        return i
    else:
        return i - 1

ls = []
for f in range(n):
    wn = win_num(f+1, k)
    ls.append((1/n) * (1/2)**wn)
print(sum(ls))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import math
N,K=map(int, input().split())
p=20
count=0
ans=0
for i in range(N):
  if (i+1)>=K:
    count+=1
  else:
    for j in range(20):
      if (i+1)*math.pow(2,j)>=K:
        ans+=math.pow(1/2,j)
        break
    
  
if N<K:
    print(1/N*ans)
else:
    print(count/N+1/N*ans)

Submission status: Accepted

Solution code:
import math

def getCount(K,i) :
    return math.log(K/i,2)

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

for i in range(1,N+1) :
    if i >= K :
        score += 1/N
        continue
    count = math.ceil(getCount(K,i))
    score += 1/N * (1/2)**count
print(score)

Submission status: Accepted

Solution code:
import math

N ,K = (int(i) for i in input().split())
ans = 0
for i in range(int(N)):
  if i < K:
    x = math.log2(K/(i+1))
    x_ceil = math.ceil(x)
    ans += pow(0.5,x_ceil)/N
  else:
    ans += 1/N

print(ans)

Submission status: Accepted

Solution code:
a, b = [int(i) for i in input().split()]

aaa = []

for i in range(1, a + 1):
    w = i
    cnt = 0
    while w < b:
        w = w * 2
        cnt += 1
    cntcnt = 0.5 ** cnt
    aaa.append(cntcnt)

print(sum(aaa) / len(aaa))

Submission status: Accepted

Solution code:
import math

N, K = map(int,input().split())
#N, K = 100000, 5

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


print(ans/N)

Submission status: Accepted

Solution code:
import math

N,K = map(int,input().split())
result = 0
N1 = 1.0/N
for i in range(N):
    k = i+1
    cnt = 0
    while(k<K):
        k = k*2
        cnt += 1
    result += math.pow(0.5, cnt)

print(result*N1)

Submission status: Accepted

Solution code:
def f(x, y):
    i = 1
    while x < y: i *= 2; x *= 2
    return 1 / i

n, k = map(int, input().split())
p = (max(0, n - k + 1) +
     sum(f(i, k) for i in range(1, min(k, n + 1)))) / n
print(p)

Submission status: Accepted

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

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

sum = 0
for i in range(1, N+1):
    k = math.ceil(math.log2(K) - math.log2(i)) if i < K else 0
    p =  1 / (N * math.pow(2, k))
    
    # print(str(i) + ': ' + str(k))
    sum = sum + p

print(sum)

Submission status: Accepted

Solution code:
import numpy as np
from decimal import Decimal

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

sum=0

for i in range(1,n+1):
    if i<k:
        cnt=0
        tempi=i
        while tempi<k:
            tempi*=2
            cnt+=1
        sum+=1/(n*(2**cnt))
    else:
        sum+=1/n

print(sum)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


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

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

            while i * 2 ** m < k:
                m += 1

            ans += (1 / 2) ** m

    print(ans / n)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
prob_list = []
for i in range(1, N + 1):
    coin_prob = 1.0
    while i < K:
        i *= 2
        coin_prob /= 2
    prob_list.append((1 / N) * coin_prob)
print(sum(prob_list))

Submission status: Accepted

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

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

print(sum_tmp)

Submission status: Accepted

Solution code:
import math

def main():
    n, k = [int(c) for c in 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)

main()

Submission status: Accepted

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

    
    ans = 0
    for x in range(1, N+1): # xは初期値
        kaisuu = ceil( log( K / x, 2))
        if x >= K:
            kaisuu = 0
        # print(kaisuu)
        # tmp = pow(0.5, kaisuu)
        tmp = 1/N
        for i in range(kaisuu):
            tmp *= 0.5
        ans += tmp 
    # ans /= N
    print(ans)
        

    
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

a = 0

for i in range(N):
  j = N - i
  b = 1

  while j < K:
      b /= 2
      j *= 2

  a += b

print(a / N)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
prob=0.0
if n>=k:
  prob+=(n-k+1)/n
mn=min(n+1,k)
for i in range(1,mn):
  check=i
  count=0
  while True:
    check*=2
    count+=1
    if check>=k:
      break
  prob+=pow(0.5,count)/n
print(prob)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = 0
for i in range(min(N,K-1)):
    tmp=1.0/float(N)
    now=i+1
    while now < K:
        now *= 2
        tmp /= 2
    P += tmp
if N > K-1:
    P += 1./float(N)*float(N-K+1)
print(P)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 26 17:52:43 2019

@author: nakamuratakayuki
"""
N, K = tuple(map(int,input().split()))
ans = 0

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