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

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

Submission status: Accepted

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

for i in range(n, 0, -1):
    while i*2**pow < k:
        pow += 1
    sum += 0.5**pow

print(sum/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
	t=1
	ii=i
	while ii<k:
		ii*=2
		t/=2.0
	ans+=t
ans=float(ans)/n
print(ans)

Submission status: Accepted

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


def solve(N: int, K: int):
    result = 0
    for i in range(1, N + 1):
        # print(i)
        if i < K:
            count = math.ceil(math.log2(K / i))
            result += (1 / N) * 0.5 ** (count)
        else:
            result += 1 / N
    print(result)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(1,N+1):
  j = i
  pro = 1
  while True:
    if j >= K:
      break
    else:
      j = j*2
      pro = pro / 2
  p.append(pro)

print(sum(p)/N)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

for i in range(N):
    if i+1 >= K:
        aaa += 1.0/N
    else:
        aaa += (1/N)*((1/2)**math.ceil(math.log2(K/(i+1))))
print(aaa)

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
import math

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

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

base_min = min(ans_base)
ans = 0
for j in range(N):
    ans += (1 / 2) ** (ans_base[j] - base_min)

ans *= (1 / N) * (1 / 2) ** base_min
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N,K=map(int,input().split())
Ans=0
if N<K:
    for i in range(1,N+1):
        p=math.ceil(math.log(K/i,2))
        Ans+=(1/N)*(1/2)**p
else:
    for i in range(1,K):
        p=math.ceil(math.log(K/i,2))
        Ans+=(1/N)*(1/2)**p
    for i in range(K,N+1):
        Ans+=(1/N)

print(Ans)

Submission status: Accepted

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

P=[0]*N
for i in range(N):
  s=i+1
  k=0
  while s<K:
    s*=2
    k+=1
  P[i]=(1/N)*(1/2)**k

print(sum(P))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
# N: サイコロの綿の数
# K: 相手の得点
p=0
for n in range(1,N+1):
    s=1/N
    while n<K:
        n*=2
        s*=0.5
    #print(n,s)
    p+=s
print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC126-C

n,k = map(int,input().split())
coin_count = 0
dice_count = 0
def func(point,cointoss): #何回コインを投げるかを再帰でカウント
	if point >= k: #終了条件:点数がkに達した
		return cointoss #コインを投げた回数を返す
	return func(point*2,cointoss+1) #ポイントを２倍にして、カウント+1

for i in range(1,n+1):
	if not i >= k:
		coin_count += (1/2)**func(i,0) #１事象ごとに確率を算出
	else: #サイコロを投げた時点でkを超えてた
		coin_count += 1

print(coin_count/n) #nで割って確率を算出

Submission status: Accepted

Solution code:
import math

n,k = map(int,input().split())
coin_count = 0
dice_count = 0
def func(point,cointoss):
	if point >= k:
		return cointoss
	return func(point*2,cointoss+1)

for i in range(1,n+1):
	if not i >= k:
		coin_count += (1/2)**func(i,0)
	else:
		coin_count += 1

print(coin_count/n)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def solve(n, k):
    p = 0
    for i in range(1, n + 1):
        q = 1
        j = i
        while j < k:
            q /= 2
            j *= 2
        p += q / n
    return p
print('%.12f' % solve(*map(int, input().split())))

Submission status: Accepted

Solution code:
N, K = [int(x) for x in input().split()]
ans = 0
for i in range(1, N+1):
    cnt = 1
    if (i >= K):
        ans += (1/N)
        continue
    tmp = i
    while(True):
        tmp *= 2
        if (tmp >= K):
            break
        cnt += 1
    ans += (1/N * (1/2 ** cnt))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = []
for i in range(1, N+1):
    cnt = 0
    j = i
    while j < K:
        cnt += 1
        j *= 2
    ans.append(1 / (N * (2 ** cnt)))
print(sum(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 += (0.5 ** math.ceil(max(math.log2(K / i), 1)))
    else:
        ans += 1
print(ans / N)

Submission status: Accepted

Solution code:
import math

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

ans = 0

if N < K:
    for a in range(N):
        t = math.log2(K)-math.log2(a+1)
        i = math.ceil(t)
        ans += (1/N) * (0.5 ** i)

else:
    for a in range(N):
        if a+1 >= K:
            ans += (1/N)
        else:
            t = math.log2(K)-math.log2(a+1)
            i = math.ceil(t)
            ans += (1/N) * (0.5 ** i)

print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,raw_input().split())
ans = float(0)
tmp = 0
con = 0
for i in range(1,N+1):
  tmp = i
  for j in range(0,K,i):
    if tmp >= K:
      break
    tmp = tmp * 2
    con = con + 1
  ans = ans + (1.0/2.0)**con * (1.0/N)
  con = 0
  tmp = 0
print ans

Submission status: Accepted

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

Prolist = []

for i in range(1,N + 1):
	Value = i
	Pro = 0
	while Value < K:
		Value = Value * 2
		Pro += 1
	Prolist.append(Pro)

total = 0

for i in Prolist:
	total += (1 / N) * 2 ** (-i)
	
print(total)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

to = 0
for i in range(1, n+1):
	cnt = 0
	num = i
	while i < k:
		i *= 2
		cnt += 1
	to += (1/n * (1/2)**cnt)

print(to)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
count = 0
for i in range(1, n+1):
  a = max(0, math.ceil(math.log2(k/i)))
  count += 1 / (n * 2**a)
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum_prob)

Submission status: Accepted

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

answer = 0

for dice in range(1,N+1):
    count = 0
    point = dice
    while point < K:
        point = point*2
        count = count + 1
    answer = answer + (1/N * 0.5**count)
    
print(answer)

Submission status: Accepted

Solution code:
import math


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


main()

Submission status: Accepted

Solution code:
import math


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


main()

Submission status: Accepted

Solution code:
import math


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


main()

Submission status: Accepted

Solution code:
import math


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


main()

Submission status: Accepted

Solution code:
import math


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


main()

Submission status: Accepted

Solution code:
import math


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


main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

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

x = np.arange(1,N+1,dtype=np.int64)
need = np.zeros(N,dtype=np.int32)

for _ in range(20):
    target = (x <= K-1)
    x[target] <<= 1
    need[target] += 1

counter = np.bincount(need,minlength=20)
power = np.full(20,1/2,dtype=np.float64); power[0] = 1; np.cumprod(power,out=power)

answer = (counter * power).sum() / N
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from math import log2
from operator import mul


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    MAX_SHIFT = int(log2(K) + 1)
    print(sum(reduce(mul, (0.5
                           if i << j < K
                           else end_of_loop()
                           for j in range(MAX_SHIFT)), 1)
              for i in range(1, N + 1)) / N)
    return


main()

Submission status: Accepted

Solution code:
from functools import reduce
from math import log2
from operator import mul


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    MAX_SHIFT = int(log2(K) + 1)
    print(sum(reduce(mul, (0.5
                           if i << j < K
                           else end_of_loop()
                           for j in range(MAX_SHIFT)), 1 / N)
              for i in range(1, N + 1)))
    return


main()

Submission status: Accepted

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


for i in range(1,N+1):
    x=0

    while True:

        if K <= i*(2**x):
            ans+= (1/N)*((1/2**x))
            break

        x+=1
        
        

print(ans)

Submission status: Accepted

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

probability = 0
for i in range(1,n+1):
  if i < k:
  	probability+=1/(n*(2**(math.ceil(math.log2(k/i)))))
  else:
  	probability+=1/n
  
print(probability)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

n,k = [int(x) for x in stdin.readline().rstrip().split()]

point = 0
kaku = 0.0

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

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    print(sum(reduce(mul, (0.5
                           if i << j < K
                           else end_of_loop()
                           for j in range(K)), 1 / N)
              for i in range(1, N + 1)))
    return


main()

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul
import math


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    print(sum(reduce(mul, (0.5
                           if i << j < K
                           else end_of_loop()
                           for j in range(int(math.log2(K))+2)), 1 / N)
              for i in range(1, N + 1)))
    return


main()

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    print(sum(reduce(mul, (0.5
                           if i << j < K
                           else end_of_loop()
                           for j in range(len(bin(K)) - 2)), 1 / N)
              for i in range(1, N + 1)))
    return


main()

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    print(sum([reduce(mul, (0.5
                            if i << j < K
                            else end_of_loop()
                            for j in range(K)), 1 / N)
               for i in range(1, N + 1)]))
    return


main()

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul


def main():
    N, K = map(int, input().split())
    ans = []
    lst = []
    for i in range(1, N + 1):
        lst.clear()
        for j in range(K):
            if K <= i << j:
                break
            lst.append(0.5)
        ans.append(reduce(mul, lst, 1 / N))
    print(sum(ans))
    return


main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

print(ans)

Submission status: Accepted

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

ans1=0

if n>=k:
	ans1=(n-k+1)/n
	
	ans2=0
	ans=0
	for i in range(k-1):
		j=1
		while (i+1)*2**j<k:
			j=j+1
	
		ans2=(1/2)**j
		#print(j)
		#print(ans2)
		ans=ans+ans2

	ans=ans1+1/n*ans

if n<k:
	ans2=0
	ans=0
	for i in range(n):
		j=1
		while (i+1)*2**j<k:
			j=j+1
	
		ans2=(1/2)**j
		#print(j)
		#print(ans2)
		ans=ans+ans2

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
ans=0

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

print(ans)

Submission status: Accepted

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

dict ={}
list = []

for i in range(n, 0,-1): # Nから１までのN個の”出目”のリストを作成
    list.append(i)
#print(list)

count_dict = {}
sum = 0
count = 0
i = 0
while(i <= len(list)-1):
    if k / list[i]  <= 2 ** count:
        #print("list is", list[i])
        #print("count is", count)
        #sum += 1 / (2 ** count)
        if count not in count_dict:
            count_dict[count] = 1
        else:
            count_dict[count] += 1
        #print("sum is", sum)
        i += 1
    else:
        count += 1

max_count = max(count_dict)
#print(count_dict)
for i in range(max_count + 1):
    #print(i)
    if i in count_dict:
        sum += count_dict[i] / (2 ** i)
        #print(sum)

print(sum/n)

Submission status: Accepted

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

if K == 1:
    print(1)
    exit()

if N < K:
    P = 0
    for i in range(1, N + 1):
        temp = 1
        while i * (2 ** temp) < K:
            temp += 1
        P += (1 / N) * (1 / 2) ** temp
else:
    P = (N - (K - 1)) / N
    for i in range(1, K):
        temp = 1
        while i * (2 ** temp) < K:
            temp += 1
        P += (1 / N) * (1 / 2) ** temp
print(P)

Submission status: Accepted

Solution code:
import math

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

if K==1:
    print(1)
    exit()

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

Submission status: Accepted

Solution code:
import numpy as np
N , K = map(int,input().split())
ans = 0
for i in range(1 , N + 1):
    j = i
    idx = 0
    while j < K:
        j *= 2
        idx += 1
    ans += 1 / N * np.power(1 / 2 , idx)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

# サイコロだけで勝つ確率
prob = max(0,(N-K+1)/N)
log_2_K = math.log2(K)

for dice in range(1,min(K,N+1)):
    prob += (1/N)*(1/2**(math.ceil(log_2_K - math.log2(dice))))

print(prob)

Submission status: Accepted

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
class Dice:
    def __init__(self,point,count):
        self.point = point
        self.count = count
dice = [Dice(i, 0) for i in range(1,n+1)]
p = []
for i in range(n):
 while 1<= dice[i].point <= k-1:
    dice[i].point *= 2
    dice[i].count += 1

 p.append(0.5 ** dice[i].count)

print(sum(p) / n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n,k = map(int, input().split())
m = n
ans = 0
if n >= k:
  ans += (n-k+1)/n
  m = k-1

p=2
while m > 0:
  if m * p >= k:
    a = m - math.ceil(k/p) + 1
    ans += a/n/p
    m -= a
  p *= 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if N >= K:
  s = (N-K+1) / N
else:
  s = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

count = 0.

for i in range(1,num+1):
    if i <= k-1:
        times = np.log2(k/i)
        if times != int(times):
            times = int(times) +1
        else:
            times = int(times)
        count += (1/num) * (1/2)**times
    elif i >= k:
        count += 1/num
print(count)

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)*min((1/2)**math.ceil(math.log2(K/i)),1)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
from decimal import Decimal
N,K=map(int,input().split())
ans = 0
for i in range(1,N+1):
    if i >=K:
        ans+=N-i+1
        break
    tmp = i
    t_k = 1
    while tmp < K:
        tmp = tmp*2
        t_k = t_k*2
    ans += Decimal(1/t_k)
print(Decimal(ans/N))

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = []
for i in range(1,n+1):
    ti = i
    pn = 0
    while ti < k:
        ti *= 2
        pn += 1
    p.append(pn)

res = 0
for pn in p:
    res += 1/(2** pn)

print(res / n)

Submission status: Accepted

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

sum_pro = 0 
for i in range(N):
  i_ = i+1
  if(i_ < K):
   p_i = math.ceil(math.log2(K/i_))
   sum_pro += (1/(2**p_i))*(1/N)
  else:
   sum_pro += 1/N
                
print(sum_pro)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
win = 0
if N >= K:
    for i in range(1,K):
        #最初に出た目がi(1 <= i < K)の時のKを超える確率の和を求める
        j =0
        while i*(2**j) < K:
            #勝負に勝つのは最初に出た目iを2のj乗した時にKを超える時
            j +=1
        win += 1/((2**j)*N)
    #サイコロを振っただけで勝ちが確定する確率
    win += (N-K+1)/N
else:
    for l in range(1,N+1):
        #最初に出た目がl(1 <= l <= N )の時Kを超える確率の和を求める
        m = 0
        while l*(2**m) < K:
            #勝負に勝つのは最初に出た目lを2のm乗した時にKを超える時
            m +=1
        win +=1/((2**m)*N)

print(win)