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_list = list()
for i in range(1, N+1):
  index = 0
  count = 0
  while i*(2**index) < K:
    index += 1
    count += 1
  ans_list.append(count)

ans = list(map(lambda x:0.5**x,ans_list))


print(sum(ans)/N)

Submission status: Accepted

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

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

print(format(rem, '.12f'))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
for i in range(1, n + 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())

import math

ans = 0
for n in range(1, N+1):
    continue_num = max(math.ceil(math.log(K, 2) - math.log(n, 2)), 0)
    ans += (1/N) * (1/2)**continue_num
    
print(ans)

Submission status: Accepted

Solution code:
def f(n,k):
  total = 0
  
  for u in range(1, n + 1):
    prob = 1.0/n 
    start = u
    p = 0
    while(start < k):
      start *= 2
      p+=1
    prob *= (0.5) ** p
    total += prob
  return total

n,k = map(int ,raw_input().split(' '))
print f(n,k)

Submission status: Accepted

Solution code:
from math import ceil, log, pow

def mi():
    return map(int, input().split())

def main():
    N, K = mi()
    ans = 0
    for i in range(1, N+1):
        ans += pow(0.5, max(0, ceil(log(K, 2)-log(i, 2))))/N
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

total = 0
for i in range(1, n+1):
    tmp = max(math.ceil(math.log(k/i, 2)), 0)
    total += 0.5 ** tmp

print(total / n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

def f(x, y):
    return math.ceil(math.log2(y / x))

ans = 0
for i in range(1, min(N, K) + 1):
    temp = (0.5) ** f(i, K)
    ans += temp
ans /= N

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

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    ans = 0.0

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

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

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

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

print(res/N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()


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

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

    ans = ans / N
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

B = [[] for _ in range(N)]
for i, a in enumerate(range(1, N+1)):
    B[i] = max(math.ceil(math.log2(K/a)), 0)
#print(B)

ans = 0
for b in B:
    ans += 1/2**b
print(ans/N)

Submission status: Accepted

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

ans = 0
for i in range(n):
    tmp = 1 / n
    score = i + 1
    while score < k:
        score *= 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):
    num = 0
    while(True):
        if i*(2**num)>=k:
            ans += (1/n) * ((1/2)**num)
            break
        num += 1
print(ans)

Submission status: Accepted

Solution code:
def getCount(a, b):
	count = 0
	while(True):
		if a < b:
			a = a*2
			count += 1
		else:
			return count

  
def answer(n, k):
    posibility = 0
    if (n >= k):
        posibility = 1/n * (n-k+1)
        for i in range(1, k):
            posibility += ((1)/(n))*((1/2)**(getCount(i, k)))
    else:
        for i in range(1, n+1):
            count = (getCount(i, k))
            posibility += 1/n*((1/2)**(getCount(i, k)))
    return posibility
        
n, k = map(int, input().split())
print(answer(n, k))

Submission status: Accepted

Solution code:
x,y=list(map(int, input().split()))
a=0
b=0
p=0
ans=0
for i in range(1,x+1):
	a=i
	p=2**20
	while a<y:
		a=a*2
		p=p/2
	ans=ans+p
print(ans/(2**20)/x)

Submission status: Accepted

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

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

Submission status: Accepted

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

probability = 0
for i in range(1,n+1):
    p = 1/n
    p_head = 1/2
    flips = 0
    prob = p * p_head**flips
    score = i
    
    while score < k:
        flips += 1
        prob = p * p_head**flips
        score = score * 2

    probability += prob


print(probability)

Submission status: Accepted

Solution code:
import math

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

# ans = (1 / n) * (1 / 2)**math.floor(math.log(k, 2) + 1)

# for i in range(2, n + 1):
#     d = math.floor(math.log(k, i))
#     ans += (1 / n) * (1 / 2)**d

ans = 0

for i in range(1, n + 1):
    v = i
    c = 0
    while True:
        if v >= k:
            ans += (1 / n) * (1 / 2)**c
            break
        v *= 2
        c += 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
S=[0]*N
for i in range(0,N):
    if i+1>=K:
        S[i]=1
    else:
        for j in range(100):
            if (i+1)*(2**(j-1))>=K:
                S[i]=1/(2**(j-1))
                break
goukei=sum(S)
print(goukei/N)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
# K以上になるためには

total = 0.0

for n in range(1, N+1):
  count = 0
  in_score = n

  while (in_score < K):
    in_score *= 2
    count += 1

  total += 1 / N * (0.5)**count

print(total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

sum = 0
for i in range(N):
    X = math.log2(K/(i+1))
    X = math.floor(X) if X % 1 == 0 else math.floor(X+1)
    #print(X, i, K)
    X = X if X > 0 else 0
    sum += (1/N)*(1/2)**X
    
print(sum)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    
    ans = 0
    for j in range(1, n+1):
        i = 0
        while True:
            if j*(2 ** i) >= k:
                ans += 1/  (n * (2 ** i))
                break
            else:
                i += 1
            
    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):
    s=i
    m=1
    while 1<=s and s<=k-1:
        m*=0.5
        s*=2
    ans+=m
print(ans/n)

Submission status: Accepted

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

# 確率
per = 0

for i in range(N):
	# 初期値
	tmp_val = i + 1

	# Kを超えたら終了
	tmp_cnt = 0
	while(tmp_val < K):
		tmp_val *= 2
		tmp_cnt += 1
	
	per += 1 / (N * 2**tmp_cnt)

print(per)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC126-C
import numpy as np
n,k = map(int,input().split())
cnt = 0
#1/サイコロの目の総数 = m
m =  1/n
for i in range(1,n+1):
    #i*2^t >= k → t >= (log2k - log2i)
    t = np.ceil((np.log2(k) - np.log2(i)))  
    #print("t:",t)
    if i < k:
        cnt += m * (0.5)**t
    else:
        cnt += m
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

    ans += 0.5**j / N

print(ans)

Submission status: Accepted

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

DP = [-1] * (max(N, K) + 10)
ans = 0
for i in range(1, N+1)[::-1]:
    cnt = 0
    n = i
    while n < K and DP[n] < 0:
        n *= 2
        cnt += 1
    if n < K:
        if DP[n] >= 0:
            DP[i] = (1/2) ** cnt * DP[n]
        else:
            DP[i] = (1 / 2) ** cnt
    else:
        DP[i] = (1/2) ** cnt
    ans += DP[i]
print(ans/N)

Submission status: Accepted

Solution code:
def main():
    N,K = map(int, input().split())
    
    l=[]
    
    for i in range(1,N+1):
        if i < K:
            m=i
            j=0
            while m<K:
                j+=1
                m = i*(2**j)
            l.append(1/(N*(2**j)))
        else:
            l.append(1/N)
    print(sum(l))
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
prob = 0
for i in range(1,n+1):
    if i <= k-1:
        x = math.floor(1+math.log2(((k-1)/i)))
       
        prob += (1/2)**x
    else:
        prob += 1
print(prob/n)

Submission status: Accepted

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

def func(ini):
    # さいころのめがiniのとき
    if ini >= K:
        per = 1 / N
        return per
    count = 0
    point = ini
    while point <= K - 1:
        point *= 2
        count += 1
    per = 1 / (N * 2**count)
    return per
ans = 0
for i in range(1, N+1):
    ans += func(i)
print(ans)

Submission status: Accepted

Solution code:
def main():
    N,K = [int(x) for x in input().split()]
    prob = 0
    for i in range(N):
        dice=i+1
        coin = 0
        while dice < K:
            dice *= 2
            coin += 1
        prob += float(1/N) * 0.5**coin
    print(prob)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

A=[]
cnt=0
def count(i,k):
    cnt=0
    while k>i:
        i=i*2
        cnt+=1
        
    return cnt

pro=0

for i in range(1,n+1):
	pro+=(1/2)**count(i,k)
print(pro/n)

Submission status: Accepted

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

    ans = 0

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (
    acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians,
    sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


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


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


n, k = invr()
res = 0
for i in range(1, n+1):
    if i > (k-1):
        res += 1/n
    else:
        x = ceil(log2((k)/i))
        res += (1/n) * (1/2)**x
print(res)

Submission status: Accepted

Solution code:
from math import ceil,log2
n,k=map(int,input().split())
ans=0
for i in range(n):
    ans+=(1/n)*(1/2)**max(0,ceil(log2(k/(i+1))))
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 < K:
        tmp /= 2
        i *= 2
    ans += tmp

ans /= N
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

    elif i<k:
        lose=0
        count=n
        while i<k:
            count*=2
            i*=2
        lose+=count
        ans+=float(1/lose)

print(ans)

Submission status: Accepted

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


win=0
lose=0
COUNT=0
ans=0
for i in range(1,n+1):
    if i>=k:
        win=0
        lose=0
        win+=1
        lose+=n-1
        ans+=float(win/(win+lose))

    elif i<k:
        win=0
        lose=0
        count=n
        win+=1
        while i<k:
            count*=2
            i*=2
        lose=lose+count-1
        ans+=float(win/(win+lose))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
coin = [0.5**k for k in range(10**5)]
ans = 0
for i in range(1,N+1):
    x = 0
    while(True):
        if i*(2**x) >= K:
            ans += 1/N * coin[x]
            break
        else: x += 1

print(ans)

Submission status: Accepted

Solution code:
import math

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

for i in range(1,N+1):
    tmp = math.log(K/i, 2)
    x = int(math.log(K/i,2))
    if i >= K:
        ans += 1/N
    else:
        if tmp - x != 0:
            x += 1
        ans += 1/N * (0.5)**x

print(ans)

Submission status: Accepted

Solution code:
import decimal
import math

N, K = map(int, input().split())
#coin = [decimal.Decimal('0.5')**k for k in range(10**4)]
ans = 0

for i in range(1,N+1):
    tmp = math.log(K/i, 2)
    x = int(math.log(K/i,2))
    if i >= K:
        ans += 1/N
    else:
        if tmp - x != 0:
            x += 1
        ans += 1/N * (0.5)**x

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n,k=map(int, input().split())
    point = 0

    ans = 0
    kita = [(int(i)+1) for i in range(n)]
    for i in kita:
        tmp  = 0
        tmp2 = i
        while tmp2 < k:
            tmp2 *= 2
            tmp+=1
        ans = ans + ((0.5)**tmp)*(1/n)
    print(ans)






if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

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

ans = 0
for i in range(1,n+1):
    if i >= k:
        ans += float(1 / n)
    else:
        ans += (1 / (2 ** math.ceil(math.log(k / i, 2)))) * (1 / n)
print(ans)

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)

n,k=l()
ans=0
for i in range(1,n+1):
    if(i<k):
        x=1
        while(i*(2**(x))<k):
            x+=1
        # print(i,x)
        ans+=Fraction(1,n)*(Fraction(1,2)**x)
    else:
        ans+=Fraction(1,n)
print(ans.numerator/ans.denominator)

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:
        c += 1
        score = score*2
    
    ans += (1/n)*((0.5)**c)

print(ans)

Submission status: Accepted

Solution code:
import math

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

if n<= k-1:
  for i in range(1,n+1):
    ans += 0.5**(math.ceil(math.log2(k/i)))
    
  print(ans*(1/n))
  
else:
  for j in range(1,k):
    ans += 0.5**(math.ceil(math.log2(k/j)))
    
  print(ans*(1/n) + ((n-k+1)/n))

Submission status: Accepted

Solution code:
N, K=map(int, input().split())
import math
def touhiwa(n):
  ans=0
  for i in range(1, n+1):
    r=max(0,math.ceil(math.log2(K/i)))
    ans+=0.5**(r)
  return ans
print(touhiwa(N)/N)

Submission status: Accepted

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

for i in s:
    x = i[0]
    c = 0
    while x < k:
        x *= 2
        c += 1
    s[i[0]-1].append(c)

for i in s:
    ans +=1/n*(1/2)**i[1]

print(ans)

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
"""
1～6で場合わけ
"""
log2k = math.log(k, 2)
ans = 0
for i in range(1, n+1):
	target = math.ceil(log2k - math.log(i, 2))
	if target >= 1:
		ans += 1/(2**target)
	else:
		ans += 1
print(ans/n)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
two=[i for i in range(20)]
for i in range(20):
    two[i]=2**i
res=0
for i in range(1,N+1):
    for j in two:
        if i*j>=K:
            res+=1/(j*N)
            break
print(res)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

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

p = 0

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

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

print(ans)

Submission status: Accepted

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

l=[]
point=k
l.append(k)
while point>1:
    if point%2==0:
        point=point//2
    else:
        point=(point//2) +1
    l.append(point)

m=len(l)

if n>=k:
    ans1=0
    for i in range(m-1):
        count=l[i]-l[i+1]
        prob=0.5**(i+1)
        ans1+=prob*count
    ans=ans1+(n-k+1)
elif n==1:
    countn=0
    nn=n
    while nn<k:
        nn=nn*2
        countn+=1
    ans=0.5**countn
else:
    ans2=0
    for i in range(m-1):
        if n>=l[i]:
            b=i
            break
        else:
            continue
        break
    ans2+=((0.5)**b)*(n-l[b]+1)
    for i in range(b,m-1):
        count=l[i]-l[i+1]
        prob=0.5**(i+1)
        ans2+=prob*count
    ans=ans2



print(ans/n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
from math import log2,ceil

n,k=n1()

ans=0
for i in range(1,min(n,k)+1):
    a=k/i
    b=0.5**ceil(log2(a))
    ans+=b

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    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)

resolve()

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    count = 0
    lc = list()
    res = 0
    for i in range(1, n+1):
        while i < k:
            i = i * 2
            count += 1
            if i >= k:
                lc.append(count)
                count = 0
    diff = n - len(lc)
    for i in range(len(lc)):
        res += 1/n * (1/2 ** lc[i])
    res += diff/n
    print(res)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def resolve():
    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)

resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

l = [None] * N
b = 0
for i in range(1, N + 1):
    a = i
    b = 0
    while a < K:
        a *= 2
        b += 1
    l[i - 1] = b

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

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
sum_value = 0
for i in range(1,N+1):
    if(i>=K):
        sum_value = sum_value+1/N
    else:
        for j in range(1,18):
            if(i*(2**j)>=K):
                sum_value=sum_value+((1/N)*(1/(2**j)))
                break
print(sum_value)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
w = max((n-k+1) / n, 0)
coin_win = 0
for i in range(1, min(k, n+1)):
    for x in range(1, 18):
        if i * (2 ** x) >= k:
            coin_win += 1 / (2 ** x)
            break
if k != 1:
    print(w + (1-w) * coin_win / min(k-1, n))
else:
    print(w)

Submission status: Accepted

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

ans = 0
for i in range(n):
  for j in range(21):
    if  (i+1)*(2**j) >= k:
      break
  ans += 1/(n * 2**j)
  
  if j == 0:
    break
    
ans += (n-i-1)/n
print(ans)

Submission status: Accepted

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

x=0
ans=0

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

print(ans)

Submission status: Accepted

Solution code:

import numpy as np

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

result = []

for i in range(n):
    num = i+1
    count = 0
    while True:
        if num >= k:
            result.append(count)
            break
        num *= 2
        count += 1


prob = 0

for j in result:
    prob += (1/n) * (0.5)**j

print(prob)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(sum(ans))

Submission status: Accepted

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

ans = 0
cout = 0
while True:
  if N - K >= 0:
    ans += (N-K+1) / (2**cout)
    N = K - 1
  if K == 1:
    break
  K = (K+1) // 2
  cout += 1
print(ans / N_)

Submission status: Accepted

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

import math

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

ans = 0
for i in range(1, n+1):
    x = max(0, math.ceil(math.log(k/i, 2)))
    # print(x)
    ans += 1/n*(0.5)**x
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
Psum = 0
for n in range(1,N + 1):
  point = n
  Pn = 1/N
  while(point <= (K - 1)):
    point *= 2
    Pn /= 2
  Psum += Pn
print(Psum)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import ceil, log2

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

if N < K:
    for n in range(1, N + 1):
        p += (1 / N) * (1 / 2) ** ceil(log2(K / n))
else:  # N >= K
    for n in range(1, K):
        p += (1 / N) * (1 / 2) ** ceil(log2(K / n))
    for n in range(K, N + 1):
        p += (1 / N)

print(p)

Submission status: Accepted

Solution code:
from sys import stdin
import math
def LI(): return list(map(int,stdin.readline().rstrip().split()))

tmp = LI()
n,k = [tmp.pop(0) for _ in range(2)]
score = -1
ans = 0
for i in range(1,n+1):
    if k <= i:
        ans += 1/n
    else:
        x = math.log2(k/i)
        ix = int(x)
        if ix<x:
            ix += 1
        ans += pow(1/2,ix)/n

print(ans)

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