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())
d = {}
ans = 0

for i in range(18):
    d[i] = 0
l = [2**i for i in range(18)]

for i in range(1,n+1):
    kk = i
    c = 0
    while(kk < k):
        c += 1
        kk *= 2
    else:
        d[c] += 1
else:
    for ind,val in d.items():
        ans += val*((1/2)**ind)
    
    print(ans/n)

Submission status: Accepted

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

Submission status: Accepted

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

base = 1 / n
ans = 0
for i in range(1, n+1):
    if i >= k:
        ans += base
        continue

    cnt = 0
    while 1:
        i *= 2
        cnt += 1
        if i >= k:
            break

    ans += base * pow(0.5, cnt)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

max_t = int(ceil(log2(K)))

cnt = 0
for n in range(1, N + 1):
    t = max(int(ceil(log2(K / n))), 0)
    cnt += 2 ** (max_t - t)

print (cnt / 2 ** max_t / N)

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

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

prob=0
for i in range(1, N+1):
  counter=0
  while i*pow(2, counter)<K:
    counter+=1
    
  prob+=pow(1/2, counter)/N
  
print(prob)

Submission status: Accepted

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
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):
    if k <= i:
        ans += 1/n
    else:
        cnt = 0
        m = i
        while m < k:
            m *= 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, n+1):
  tmp = 1
  while i*tmp < k:
    tmp *= 2
  ans += 1/tmp
print(ans/n)

Submission status: Accepted

Solution code:
#最近だいぶC問題が簡単に感じるようになってきたのは
#問題のあたりの問題か、成長か
#でも、場合わけ足りないこと多いから注意
n,k = map(int,input().split())
import math

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ret = 0.0
for i in range(1, n + 1):
    tmp = 1.0 / n
    now = i
    while now < k:
        now *= 2
        tmp /= 2.0
    ret += tmp
print("{0:0.12f}".format(ret))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in range(1, N+1):
    point = i
    tmp = 1/N
    while True:
        if point >= K:
            ans += tmp
            break
        point *= 2
        tmp *= (1/2)

print(ans)

Submission status: Accepted

Solution code:
import math
import copy
import fractions
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

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

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

ans = ans/n
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n, k = map(int, input().strip().split(' '))
p = 0
for i in range(n):
  coin = np.ceil(np.log2( k/(i+1) ))
  if coin > 0:
    p = p + 1.0/n * 0.5**coin
  else:
    p = p + 1.0/n
print(p)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

A = K

ans = 0

i = 0
last = K
while True:
    i += 1
    A = K/pow(2,i)
    num = last - math.ceil(A)
    if math.ceil(A) <= N:
        if last-1 >= N:
            num = N - math.ceil(A) + 1
        ans += (num / N) / pow(2,i)
    
    last = math.ceil(A)
    if A <= 1:
        break
    
    
if N >= K:
    ans += (N - K + 1) / N
    
print('{:.14g}'.format(ans))

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
def get_num_coin(ini_point, k):
  n = 0
  tmp_point = 0
  while tmp_point <= k-1:
    n+=1
    tmp_point = ini_point*(2**n)
  return n

n, k = map(int, input().split())
ans = 0
for ini_point in range(1, n+1):
  if ini_point >= k:
    ans += 1/n
    continue
  else:
    num_coin = get_num_coin(ini_point, k)
    ans += 1/n * (0.5**num_coin)
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
readline = sys.stdin.readline
N, K = list(map(int, readline().split()))

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

print(ans)

Submission status: Accepted

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

for i in range(N):
    for j in range(0,2**10):
        total=(i+1)*(2**j)
        if(total>=K):
            break

    bunsu[i]=1/(N*(2**j))

print(sum(bunsu))

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

def main():

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

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

result = 0
for i in range(N):
    score = i + 1
    coin_toss_count = 0
    while score < K:
        coin_toss_count += 1
        score = score * 2
    result += (1 / N) * (0.5 ** coin_toss_count)

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

import math

def main(): 

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 0.0
for i in range(1,n+1):
    if i >= k:
        ans += (1/n)
    else:
        get = (1/n)
        val = i
        while val < k:
            val *= 2
            get *= (1/2)
        ans += get
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

for i in range(1, n+1):
    needed_times = math.ceil(math.log2(math.ceil(k/i)))
    win_rate += 1/n * 0.5 ** needed_times

print(win_rate)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
list = range(1,N+1)
ans=[0]*N
i = 1
j = 0

for n in reversed(list):
    while n*i < K:
        i = i*2
    ans[n-1] = i
for k in ans:
    j += 1/k*1/N

print(j)

Submission status: Accepted

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

def main(N,K):
    ans = 0
    for i in range(1,N+1):
        tmp = 1/N
        score = i
        count = 0
        while(K>score):
            score *= 2
            count += 1
        tmp /= (2**count)
        ans += tmp
    print(ans)

if __name__ == '__main__':
    N, K = map(int, input().split())
    main(N,K)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,n+1):
  t = i
  while i < k:
    i = 2*i
    a[t-1] = (1/2)*a[t-1]
print((1/n)*sum(j for j in 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:
        temp=i*1
        cnt=1
        while temp <k:
            temp*=2
            cnt/=2
        ans+=cnt/n

print(ans)

Submission status: Accepted

Solution code:
n, k = [int(x) for x in input().split(' ')]

res = 0.0
for dice in range(1, n+1):
    tmp = dice
    cnt = 0
    while k > tmp:
        tmp *= 2
        cnt += 1
    res += (1 / n) * (0.5 ** cnt)

print(res)

Submission status: Accepted

Solution code:
import math
def dice_and_coin(n,k):
    ans = 0.0
    for i in range(1,n+1):
        if i >= k:
            ans += 1/float(n)
        else:
            flip = math.log(k,2) - math.log(i,2)
            ans += 1/float(n) * (0.5 ** math.ceil(flip))
#        print("%f = 1/%d * (1/2 ** %d)"%(ans, n,math.ceil(flip)))
    print("{0:.10f}".format(ans))

if __name__ == '__main__':
    n,k = map(int,raw_input().split())

    dice_and_coin(n,k)

Submission status: Accepted

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

ans = 0
for i in range(1, N+1):
  if i >= K:
    ans += 1/N
  else:
    ans += 1/N * 0.5 ** math.ceil(math.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):
    num = 0
    # iに２の何乗を掛けるとKを超えるか
    j = 0
    while True:
        if i * 2 ** j >= K:
            num = j
            break
        j += 1
    ans += (1/N) * (1/2) ** num
print(ans)

Submission status: Accepted

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

    prob = 0
    if K-1 < N:
        prob += (N-K+1)
    sub = 0
    for i in range(1, min(N, K-1)+1):
        count = 0
        v = i
        while v < K:
            v*= 2
            count += 1
        sub += pow(0.5, count)
    return (prob + sub)/N

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N,K=map(int,input().split())
def sis(K,N):
    n1=K/N
    n2=math.log2(n1)
    n3=int(n2)
    if n2>n3:
        n3+=1
    return n3
ans=0
for i in range(N):
    if i>=K:
        ans+=1/N
    else:
        ans+=1/((2**sis(K,i+1))*N)
print(ans)

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
res = 0
for i in range(1, n+1):
    a = k / i
    b = format(math.ceil(a) - 1, 'b')
    num = 0 if b == '0' else len(b)
    res +=  (1/n) *  (1/2)**num
print(res)

Submission status: Accepted

Solution code:
import math

def main():
  pos=0
  n,k=map(int,input().split())
  nmen=1/n

  for i in range(1,n+1):
    ajs=(-(-math.log2(k/i)//1))
    if ajs<=0: ajs=0
    pos+=nmen*0.5**ajs
  #  print(ajs)
  print(pos)
  
if __name__ == "__main__":
  main()

Submission status: Accepted

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

print( ans*(1/n) )

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from math import log2, ceil

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

    ans = 0
    for i in range(1, N+1):
        n = ceil(log2(K) - log2(i))
        if n > 0:
            ans += 0.5 ** n
        else:
            ans += 1

    return ans / N

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

Submission status: Accepted

Solution code:

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

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

#    print(count)
    ans += (1/n * (0.5 ** count))

print(ans)

Submission status: Accepted

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

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

	for i in range(1, K):
		j = math.floor((math.log2((K - 1) / i)) + 1)
		ans += (1 / N) * (1 / 2) ** j

else:
	for i in range(1, N + 1):
		j = math.floor((math.log2((K - 1) / i)) + 1)
		ans += (1 / N) * (1 / 2) ** j

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

S = 0

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

print(S)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,K = II()

ans = 0.0

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

#dp用の表
dp=[None for i in range(n+1)]

#nから1まで一つずつ埋めていく
for i in range(n):
    i=n-i
    if i>=k:
        dp[i]=0
    else:
        j=2*i
        if j<=n:
            dp[i]=dp[j]+1
        else:
            count=1
            while j<k:
                count+=1
                j=2*j
            dp[i]=count
            
# print(dp)

prob=0
for i in range(n):
    a=dp.pop()
    prob+=0.5**a
print(prob/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

ans=0



for i in range(n):
  
#でためのかずがi+1のかくりつpi
#なんかい２をかけたらkを超えるか
  count=0
  score=i+1
  for j in range(30):
    if score>=k:
      break
    score=score*2
    count+=1

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

Submission status: Accepted

Solution code:
from math import ceil

# 定数
INF = float("inf")
MOD = int(1e9 + 7)

# エントリーポイント
def main():
    N, K = map(int, input().split())
    r = 0
    for n in range(1, N + 1):
        c = 0
        while n < K:
            n *= 2
            c += 1
        r += 0.5 ** c
    print(r / N)

main()

Submission status: Accepted

Solution code:
from sys import stdin
import math

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

# ケース1
if (N >= K):
	prob1 += (N-K+1) / N

# ケース2
for p in range(1, min(N+1, K)):
  prob2 += (0.5) ** math.ceil(math.log2(K/p)) / N
  
print(prob1 + prob2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(n):
    tmp = i+1
    p = 1/n
    while k > tmp:
        tmp *= 2
        p /= 2
    ans += p

print(ans)

Submission status: Accepted

Solution code:
prob = 0.0
N,K = map(int,input().split())
for n in range(1,N+1):
    num = 0
    c = n
    while c < K:
        num += 1
        c *= 2
    prob += (0.5 ** num) / N

print(prob)

Submission status: Accepted

Solution code:
import math
n, k = map(int, raw_input().split())
p = 0.0
for i in range(1,n+1):
    if i < k:
        x = math.ceil(math.log((float(k) / float(i)), 2))
        p += (float(1) / float(n)) * ((0.5) ** x)
    else:
        p += (float(1) / float(n))

print p

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 126 C
n, k = [int(el) for el in input().split(' ')]
H = []
for i in range(1, n+1):
    h = 0
    while i < k:
        i = 2*i
        h += 1
    H.append(h)

total = 1/n * sum([(1/2)**h for h in H])
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math


def solve():
    n, k = map(int, input().split())
    exp = 0
    for i in range(1,  n + 1):
        if i >= k:
            exp += 1
        else:
            dice_num = math.ceil(math.log2(k / i))
            exp += 0.5 ** dice_num
    return exp / n


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
r = 0
total = 0
for i in range(1, n + 1):
    t = i
    cnt = 0
    while True:
        if t >= k:
            total += 1 / n * (0.5) ** cnt
            break
        else:
            cnt += 1
            t *= 2
print(total)

Submission status: Accepted

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

for i in range(1,n+1):
    if i<=k-1:
        n1=i
        for j in range(1,k+1):
            n1=n1*2
            if n1<=k-1:
                continue
            else:
                win+=(1/n)*(1/2**j)
                break
    else:
        win+=1/n
        
print(win)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = 0
def two(x,y):
    for i in range(0,10**9):
        if x >= y:
            return i
        x *= 2
        
for i in range(1,n+1):
    tmp = 1/n
    pro = two(i,k)
    if pro:
        tmp *= (1/2)**pro
    else:
        pass
    ans += tmp
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

n,k=getints()

res = 0.0

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

print(res)

Submission status: Accepted

Solution code:
import math

n,k = map(int,input().split())
sum = 0
for i in range(1,n+1) :
    if i > k :
        sum += 1
    else :
        sum += math.pow(0.5,math.ceil(math.log2(k/i)))
print(sum/n)

Submission status: Accepted

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

s = []

for i in range(1,n+1):
    cnt = i
    j = 1
    while cnt < k:
        cnt = cnt *2
        j += 1
    s.append(j-1)

total = 0
for i in range(len(s)):
    p = (1/n)*(1/2)**s[i]
    total = total + p

print(total)

Submission status: Accepted

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

checker = [k]
x = k
while x > 1 :
    x /= 2
    checker.append(x)

percentage = []
for i in range(len(checker)):
    percentage.append(1/(n*2**i))

answer = 0
for i in range(1,n+1):
    for j in range(len(checker)):
        if i >= checker[j]:
            answer += percentage[j]
            break

print(answer)

Submission status: Accepted

Solution code:
# Dice and Coin
N, K = map(int,input().split())
# N サイコロの面
# K 得点
K3 = []
ans = 0
count = 0  #コイン振る回数 MAX

for i in range(1, N+1):
    K1 = i
    K2 = 0
    count = 0
    while K1 < K:
        K1 = 2 * K1
        count = count + 1
    K2 = 1/N * (1/2)**count
    K3.append(K2)

for k in range(N):
    ans = ans + K3[k]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import math

max_it=int(math.log(n, 2))+1
mn_d=min(d,n)
p=0

for i in range(1,mn_d+1):
	for j in range(1,max_it+1):
		if i*2**j>=n:
			if i<n:
				p+=1/d*0.5**j
			break

if d>=n:
	p+=(d-n+1)/d

print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0.0

p1 = min(k-1, n) / n
ans += 1.0 - p1

for i in range(1, min(k-1, n) + 1):
    p2 = 1.0 / n
    j = i
    while j < k:
        p2 *= 0.5
        j *= 2
    ans += p2

print(ans)

Submission status: Accepted

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

proba = 0
for i in range(1,N+1):
	deme = i
	con = 0
	while deme < K:
		deme *= 2
		con += 1
	proba += (1/N)*((1/2)**con)

print(float(proba))

Submission status: Accepted

Solution code:
from fractions import Fraction

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

proba = 0
for i in range(1,N+1):
	deme = i
	con = 0
	while deme < K:
		deme *= 2
		con += 1
	proba += (1/N)*((1/2)**con)

print(float(proba))

Submission status: Accepted

Solution code:
#126
from math import ceil, log
n, k = list(map(int, input().split(' ')))
rate = 0
for i in range(1,n+1):
    x = ceil(log(k/i, 2))
    if x < 0:
        x = 0
    rate += (1/n)*pow(0.5, x)
print(rate)

Submission status: Accepted

Solution code:
#126
from math import ceil, log
n, k = list(map(int, input().split(' ')))
rate = 0
for i in range(1,n+1):
    x = ceil(log(k/i, 2))
    if x < 0:
        x = 0
    rate += (1/n)*(1/2)**x

print(rate)

Submission status: Accepted

Solution code:
#126
from math import ceil, log
n, k = list(map(int, input().split(' ')))
rate = 0
for i in range(1,n+1):
    x = ceil(log(k/i, 2))
    if x < 0:
        x = 0
    rate += (1/n)*(1/2)**x
print(rate)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N, K = [int(v) for v in input().split()]
p = 0

limit = N
if N - K + 1 > 0:
    p = (N - K + 1) / N
    limit = K-1


for i in range(1, limit+1):
    f = np.ceil(np.log2(K/i))
    p += (1/N) * np.power(1 / 2, f)
print(p)

Submission status: Accepted

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

p=0.0
for n in range(1,N+1):
    need = 0
    point = n
    while point < K:
        point *= 2
        need += 1
    p+=1.0/N*pow(0.5,need)
print(p)