Problem:


Score : 300 points

Problem Statement

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

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

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

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

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

Constraints

1 ≤ N ≤ 10^5

1 ≤ K ≤ 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

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

Sample Input 1

3 10

Sample Output 1

0.145833333333

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

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

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

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

Sample Input 2

100000 5

Sample Output 2

0.999973749998



Sample input:
3 10


Sample output:
0.145833333333

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = [0] * N
p[0] = len(bin(K)) - 2
if 2 ** p[0] >= 2 * K:
    p[0] = p[0] - 1
for i in range(N - 1):
    if 2 ** p[i] * (i + 2) >= 2 * K:
        p[i + 1] = p[i] - 1
    else:
        p[i + 1] = p[i]
    if p[i + 1] == 0:
        break
ans = float(0)
for n in range(1, N + 1):
    ans += 1 / N * ((1/2) ** p[n-1])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

result = 0
for n in range(1, N + 1):
	d, x = 0, n
	while x < K:
		d += 1
		x *= 2
	result += (1 / N) * (1 / 2)**d
print(result)

Submission status: Accepted

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

result, md = 0, len("{:b}".format(K))
for n in range(1, N + 1):
	d, x = 0, n
	while x < K:
		d += 1
		x *= 2
	#print(md, n, d)
	result += (1 / N) * (1 / 2)**d
print(result)

Submission status: Accepted

Solution code:
import math

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

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

print(ans)

Submission status: Accepted

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

prb = 0
ans = 0
for i in range(1,N+1):
  #print('i=', i)
  tokuten = i
  cnt =0 
  while tokuten < K:
    tokuten = tokuten *2
    cnt += 1
  prb += 1/N * pow(0.5, cnt)
print(prb)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ri = lambda: int(input())
#rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

N,K=rl()
""" M=[0]*(max(N,K)+2)
k = K
M[k] = 1
while k > 1:
    k = k / 2.0
    ind = int(k//1)
    if k%1 == 0:
        ind -= 1
    M[ind] = 1
for i in range(K,0,-1):
    M[i] += M[i+1]
ans = 0
for i in range(1,N+1):
    ans += (1/2)**(M[i])/N
print(ans)
 """
ans = 0
for i in range(1,N+1):
    ex = 0
    point = i
    while point < K:
        ex += 1
        point *= 2
    ans += (1/2)**ex/N
print(ans)

Submission status: Accepted

Solution code:
import math

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

prob = 0
for n in range(1, N+1):
    i = int(math.log2(K/n))
    if n > K:
        i = 0
    elif not n * 2**i == K:
        i += 1
    prob += 1 / N / (2**i)

print(prob)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def turn(a,x):
	b = 0
	while a < x:
		b += 1
		a *= 2
	return b

n, k = [ int(v) for v in input().split() ]
anslist = [ 2**(-turn(i+1,k)) for i in range(n) ]


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

Submission status: Accepted

Solution code:
import math

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

l = []
for i in range(n):
    if i <= k:
        m = math.ceil(math.log2(k/(i+1)))
        l.append(1/2**m)
    else:
        l.append(1)

print(1/n*sum(l))

Submission status: Accepted

Solution code:
import math
def main():
    n,k = [int(i) for i in input().split()]
    ans = 0.0
    for i in range(1, n+1):
        # 出目
        if k <= i:
            # 出目がすでに k 以上の時
            ans += 1/n
        else:
            # それ以外
            ans += 1/n*(1/2)**math.ceil(math.log2(k/i))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

def solve():
	diceSurfaces, winBorder = [int(x) for x in input().split()]
	diceProbability = (1 / diceSurfaces)
	ans = 0
	for score in range(1, diceSurfaces + 1):
		if score >= winBorder:
			ans += diceProbability
			continue 
		needNum  = math.ceil((winBorder) / score)
		needWins = math.ceil(math.log2(needNum))
		ans += diceProbability * ((1/2) ** needWins)
	print(ans)
solve()

Submission status: Accepted

Solution code:
from math import ceil, log2

n, k = map(int, input().split())
a = sum((2 ** (-ceil(log2(k / i)))) / n for i in range(1, min(k, n + 1)))
b = (n - k + 1) / n if n >= k else 0
print(a + b)

Submission status: Accepted

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

for s in range(1,N+1):
    j = 1/N
    while s<K:
        s *= 2
        j /= 2
    out += j

print(out)

Submission status: Accepted

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

probs = []
for i in range(1, N+1):
    
    a = i
    n = 0
    while a < K:
        a *= 2
        n += 1

    p = (1/N) * (1/2)**n
    probs.append(p)

print(sum(probs))

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
if n >= k:
    answer = (n-k+1)/n
else:
    answer = 0.0

for i in range(1,min(n+1,k)):
    j = 1
    while True:
        if i*(2**j) >= k:
            answer += (0.5**j)/n
            break
        else:
            j += 1

print(answer)

Submission status: Accepted

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

def main():
	n, k = map(int, input().split())
	win_per = 0
	for i in range(n):
		count = 0
		score = i + 1
		if score <= k:
			while True:
				if score >= k:
					break
				score *= 2
				count += 1
			win_per += (1 / n) * (1 / 2)**count
		else:
			win_per += 1 / n
	print(win_per)

if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

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

a=k
b=n
count=0
halfcount=0
while(k>0.5):
    if b>=k and k%1==0:
        count+=(b-int(k)+1)/(2**halfcount)/n
        b=int(k)-1
    elif b>=k:
        count+=(b-int(k))/(2**halfcount)/n
        b=int(k)
    halfcount+=1
    k/=2
#     print(k)
#     print(count)
# print(k)
# print(int(k))
print(count)

Submission status: Accepted

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

ans = 0
for i in reversed(range(1, N+1)):
    n = 1
    # i番目のサイコロの目（=i）がKを超えるには何回コインで面を出す必要があるか
    while i < K:
        # 2倍にしている
        n = n*2
        i = i*2
    # Kを超える確率（=超えるために必要なコインが連続で表になる確率をansに加算する）
    ans += 1/n

# ansには各目が出る確率の合計が格納されているので値をN（サイコロの目の数）で割る
print(ans/N)

Submission status: Accepted

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

ans = 0
for i in reversed(range(1, N+1)):
    n = 1
    # i番目のサイコロの目（=i）がKを超えるには何回コインで面を出す必要があるか
    while i < K:
        # 2倍にしている
        n <<= 1
        i <<= 1
    # Kを超える確率（=超えるために必要なコインが連続で表になる確率をansに加算する）
    ans += 1/n

# ansには各目が出る確率の合計が格納されているので値をN（サイコロの目の数）で割る
print(ans/N)

Submission status: Accepted

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

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

  ans += workp
  
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/n

    else :
        coin = math.ceil(math.log2(k/i))
        ans += (1/n)*(1/2)**(coin)


print(ans)

Submission status: Accepted

Solution code:
def get_n(k, K):
    ruijo = k

    if k >= K:
        return 0

    for i in range(1, 1000000):
        ruijo = ruijo * 2
        if ruijo >= K:
            return i

    return -1


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

p = 0

for i in range(1, N+1):
    tmp = float(1/N) * float(1/2)**(int(get_n(i, K)))
    p = p + tmp

print(p)

Submission status: Accepted

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

import math

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

Submission status: Accepted

Solution code:
import math

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

ans = float(0)
logK = math.log(K, 2)

for n in range(1, N + 1):
    if n >= K:
        ans = ans + float(1 / N)
    else:
        prob_n = 1.0 / math.pow(2, math.ceil(logK - math.log(n, 2)))
        ans = ans + float(1 / N * prob_n)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N,K = map(int,input().split())
ans =1
p=0
for num in range(1,N+1):
    tmp = 1/N
    now = num
    while now < K:
        now *= 2
        tmp /= 2
    p += tmp
print(p)

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###


import math
N, K = mi()

#各i(1~N→-0~N-1)に何回2を掛けるとk以上になるか
ans = 0
for i in range(N):
  ans += 1 / (2 ** max(0, math.ceil(math.log2(K/(i+1)))))

print(ans / N)

Submission status: Accepted

Solution code:
from math import log2,ceil
p = 0
dice, point = map(int,input().split())
for i in range(1,dice+1):
  temp = ceil(log2(point/i))
  if temp < 0:
    temp = 0
  p += (1/2) ** temp / dice
print(p)

Submission status: Accepted

Solution code:
from math import log2, ceil

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

a = 0
for i in range(1, n + 1):
    b = max(ceil(log2(k/i)), 0)
    a += (1 / 2 ** b) / n
print(a)

Submission status: Accepted

Solution code:

n1, n2 = [int(i) for i in input().split()]

s1  = float(0)
for i1 in range(n1):
    r1 = (i1 + 1)
    c1 = 1
    if n2 <= r1:
        s1 += (1/n1)
        continue

    while True:
        r1 *= 2
        c1 = c1 * (1/2)
        if n2 <= r1:
            s1 += ((1/n1)*c1)
            break

print('{:.12g}'.format(s1))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
List = []
for i in range(1,N+1):
    if i>=K:
        List.append(0)
    else:
        tmp = i
        count = 0
        while(tmp<K):
            tmp = tmp*2
            count+=1
        List.append(count) 
        
ans = [0]*N
ans[0] = 0.5**List[0]/N
for i in range(1,N):
    if List[i-1]==List[i]:
        ans[i] = ans[i-1]
    else:
        ans[i] = (2**(List[i-1]-List[i]))*ans[i-1]#直前の答えに減った2の累乗だけ掛け算してあげる．
print(sum(ans))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  N,K=LI()
  a=1/N

  ans=0
  for i in range(1,N+1):
    c=1
    x=i
    while True:
      if x>=K:
        break
      else:
        x*=2
        c*=2

    ans+=1/c

  return ans*a

print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

probability_list = []

for i in range(N):
    if i+1 > K:
        probability_list.append(float(1))
    else:
        probability_list.append(1/2**(math.ceil(math.log2(K/(i+1)))))

print(sum(probability_list)/N)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
P = 0
for i in range(1, N + 1):
    if i > K:
        continue
    e = 0
    while i * 2 ** e < K:
        P += 1 / N * 0.5 ** (e + 1)
        e += 1
print(1 - P)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(tmp/N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def resolve():
    (N, K) = list(map(int, input().split(" ")))
    ans = 0
    for n in range(1, N+1):
        ans = ans + (1/N) * pow(2, -1*(max(0, math.ceil(math.log2(K/n)))))
    print(ans)

if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

import math

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

prob = 0
for i in range(1,n + 1):
    if i >= k:
        prob += 1/n
    else:
        ratio = math.ceil(math.log2(k / i))
        prob += (1/n) * ((1/2) ** ratio)

print(prob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
for i in range(1,n+1):
	ans_temp = 1/n
	for j in range(1000):

		if i >= k:
			ans += ans_temp
			break
		else:
			i = i * 2
			ans_temp = ans_temp/2
print(ans)

Submission status: Accepted

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

cur_coin_count = 0
cur_probability = 1

tmp = N
while True:
    if tmp >= K:
        break
    tmp *= 2
    cur_coin_count += 1
    cur_probability /= 2
ret = cur_probability

num = N-1
while num > 0:
    if num * (2 ** cur_coin_count) < K:
        cur_coin_count += 1
        cur_probability /= 2

    ret += cur_probability
    num -= 1
ret /= N
print(ret)

Submission status: Accepted

Solution code:
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
n,k= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
#これを消すとなぜかWAになる呪い
s = 0
for i in range(1,n+1):
    c = 1
    while i < k:
        i*=2
        c*=0.5
    s+=c
print(s/n)

Submission status: Accepted

Solution code:
import sys

def step_count(val, lim):
    count = 0
    while True:
        if val >= lim:
            return count
        else:
            val *= 2
            count += 1

def main():
    sinputl = sys.stdin.readline

    dice, limit = [int(x) for x in sinputl().split()]

    chance = 0.0

    for first in range(1, dice+1):
        chance += (1/dice) * (1/ 2 ** step_count(first, limit))

    print(chance)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
# stdin = open('./input.txt')
import math

N, K = stdin.readline().rstrip().split()
N = int(N)
K = int(K)
if K <= 1:
    print(1)
    exit(0)


print(sum([(1/2)**(math.floor(math.log(((K-1)/n), 2))+1) if n < K else 1 for n in range(1, N+1)]) / N)

Submission status: Accepted

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

#1-N => iが出たとする
#i * 2^(ai-1) < k <= i * 2^(ai) となる aiを求める
#ai = math.ceil(math.log(k/i, 2)) 
#勝率は(1/2)^ai
#勝率を求めるには i について平均をとればよい
pi = []
for i in range(1,n+1):
  if i < k:
    ai = math.ceil(math.log(k/i, 2))
    pi.append( ((1/2)**ai) / n )
  else:
    pi.append( 1 / n )
    
print(sum(pi))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
for n in range(1,N+1):
	p=0
	while n*2**p<K:
		p+=1
	ans+=(0.5**p)/N
print('{:.12f}'.format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

tN = N
tK = K
tP = 1
ans = 0

for i in range(20):
    #print(tN,tK,tP)
    if tN >= tK:
        if tK > int(tK):
            ans += ((tN -int(tK)) * tP)/N
            tN = int(tK)
        else:
            ans += ((tN -int(tK)+1) * tP)/N
            tN = int(tK)-1
        #print(ans)
    tP = tP/2
    tK = tK/2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

p = 0
for i in range(1,N+1):
  cnt = 0
  n = i
  while n < K:
    n *= 2
    cnt += 1
  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):
  tmp = math.floor(k/i)
  if tmp == 0:
    ans += 1/n
  elif k % i == 0 and tmp & tmp-1 == 0:
    ans += 1/(n*(2**(len(bin(tmp))-3)))
  else:
    ans += 1/(n*(2**(len(bin(tmp))-2)))
print(ans)

Submission status: Accepted

Solution code:
N, K = list(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:
#ABC 126
N,K= map(int,input().split())
ans=0
for i in range(1,N+1):
    tmp=1/N
    x = i
    while x <K:
        x*=2
        tmp/=2
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
import math

n, k = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for m in range(m)]
#light = [int(i) for i in input().split()]
#s = int(input())
#list = list(s)

#print(n, m)
#print(table)
#print(light)

p = 0.0

for i in range(n):
    j = i + 1
    if (j < k) :
        p += 2 ** ( - math.ceil( math.log2(k / j) ) )
    else :
        p += 1
p = p / n

print(p)

Submission status: Accepted

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

sum_prob = 0
for i in range(1,N+1):
  curr_score = i
  coin_heads = 0
  while curr_score < K:
    curr_score = curr_score * 2
    coin_heads += 1
  sum_prob += 1./N * (0.5)**coin_heads

print(sum_prob)

Submission status: Accepted

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

prob = 0.0
potencias = [1]
i = 1
while i < 100001:
    i *= 2
    potencias.append(i)


# print potencias
for i in xrange(1, N+1):
    if i < K:
        j = 0
        while potencias[j]*i < K:
            j += 1
        p = 1.0/(N*1.0)
        p *= (0.5**j)
        prob += p
    else:
        prob += 1.0/(N*1.0)
    
print prob

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
kli = [k]
kch = k
while True:
  if kch == 1:
    break
  kch = (kch-1)//2 + 1
  kli.append(kch)
kli.reverse()
qli = []
def f(x):
  if x > 0:
    return x
  else:
    return 0
le = len(kli)
for i in range(le-1):
  p = min(n+1,kli[i+1])
  q = p - kli[i]
  qli.append(f(q))
qli.append(f(n+1-kli[-1]))
qli.reverse()
b = 1
son = 0
for i in range(le):
  son += b * qli[i]
  b /= 2
print(son/n)

Submission status: Accepted

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

Submission status: Accepted

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

prob = 0
for now_ in range(1, N+1):
  times = 0
  if now_ >= K:
    prob += (1/N) * (N - now_ + 1)
    break
    
  while K > now_:
    now_ *= 2
    times += 1
  prob += (1/N) * (1/2)**times
print(prob)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())#n面ダイス,k点
p=0
if n >= k:
    p+=(n-k+1)/n#サイコロを振った時点で超える確率


a=n+1 if n<k else k
for i in range(1,a):#iの目がでたとき
    p_tmp=(1/n)
    j=i
    while j<k:
        p_tmp*=0.5
        j*=2
    p+=p_tmp

print(p)

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
import numpy as np
ans = []
for i in range(N):
    score = i + 1
    counter = 0
    while score <= K - 1:
        score = score * 2
        counter += 1
    ans.append((1/N)*((1/2)**counter))
print(np.sum(ans))

Submission status: Accepted

Solution code:
import math
from fractions import Fraction
N,K=map(int,input().split())
s=0
if N >= K:
  s=s+Fraction(N-K,N)
  d=0
  for i in range(K):
    a=math.log(K/(i+1),2)
    d=d+Fraction(1, 2)**(math.ceil(a))*Fraction(1, N)
else:
  d=0
  for i in range(N):
    a=math.log(K/(i+1),2)
    d=d+Fraction(1, 2)**(math.ceil(a))*Fraction(1, N)
print(float(s+d))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
cnt = 0
prob = 0
score = 0
for i in range(1, min(n+1,k)):
        score = i
        while True:
                score = score*2
                cnt += 1
                if score >= k:
                        break
        prob += 1/n * (1/2)**(cnt)
        cnt = 0
if n >= k:
        ans = (prob + (n-k+1)/n)
else:
        
        ans = prob
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n, k = map(int, input().split())
print(sum(min(1, 2 ** (-np.ceil(np.log2(k / i)))) for i in range(1, n + 1)) * (1 / n))

Submission status: Accepted

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

p = 1 / n
result = 0
for i in range(1, n + 1):
    result += min(1, 2 ** (-np.ceil(np.log2(k / i))))
print(p * result)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
count = 0
def sai(a,b):
    p = 0
    while a < b:
        a = a*2
        p = p + 1
    return p
for i in range(n):
    count = count + float((1/n)*(1/(2**(sai(i+1,k)))))
print(count)

Submission status: Accepted

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

sum = 0

for i in range(1,n+1):
    sc = i
    pr = 1/n
    while sc < k:
        sc *= 2
        pr *= 1/2
    sum += pr

print(sum)

Submission status: Accepted

Solution code:
import math

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

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

print((p + max(N-K+1, 0)) / N)

Submission status: Accepted

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

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

print(ans/N)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
    p=1#i面を振った時の確率
    score=i#現在の得点
    while score<k:
        p*=0.5
        score*=2
    ans+=p/n
print(ans)

Submission status: Accepted

Solution code:

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

s=0

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(1, min(n+1, k)):
    exp = expo(i, k)
    ans += (1/n * (1/2)**exp)

if n >= k:
    ans += ((n - (k-1)) / n)
    
print(ans)

Submission status: Accepted

Solution code:
import math

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

count = 0
now = K

while now > N :
    count += 1
    now = now / 2.

prob = 0

for i in range(1,N+1) :
    if i < now :
        for k in range(N) :
            if i * 2**k >= now :
                break
        prob += 2**(-(count + k )) / N
    else :
        prob += 2**(-count) / N

print(prob)

Submission status: Accepted

Solution code:
import math
N, k = map(int, input().split())
ans = 0
for init in range(N):
    init +=1
    n = 0
    while(init < k):
        init *= 2
        n +=1
    p = ((1/2)**n) / N
    ans +=p
print(ans)

Submission status: Accepted

Solution code:
def getindex(i):
    for a in range(K+1):
        if i*2**a >= K:
            return a

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

for i in range(1,N+1):
    x = getindex(i) if i < K else 0
    pulas = (1/N)*((0.5)**x) if x > 0 else 1/N
    result += pulas

print(result)

Submission status: Accepted

Solution code:
def kakeru(i):
    for a in range(K+1):
        if i*2**a >= K:
            return a

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

for i in range(1,N+1):
    x = kakeru(i) if i < K else 0
    pulas = (1/N)*((0.5)**x) if x > 0 else 1/N
    result += pulas

print(result)

Submission status: Accepted

Solution code:
def kakeru(i):
    for a in range(K+1):
        if i*2**a >= K:
            #print(i)
            #print(a)
            return a


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

for i in range(1,N+1):
    x = kakeru(i) if i < K else 0
    #print(x)
    pulas = (1/N)*((0.5)**x) if x > 0 else 1/N
    result += pulas
    #print(pulas)

print(result)

Submission status: Accepted

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

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

A = [max(math.ceil(math.log2((K)/(i+1))), 0) for i in range(N)]
A = [1/(2**a) for a in A]

print(sum(A)/len(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    
    ans = 0
    for i in range(N):
        coin = 1 / N
        bai = i + 1
        
        while bai < K:
            bai = bai * 2
            coin = coin / 2
        
        ans = ans + coin
    
    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=1/n
	cnt=i
	while cnt<k:
		cnt*=2
		tmp/=2
	ans+=tmp

print(ans)