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

Solution (Python):


import sys
from math import *

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))



def main():
    N, K = i2nn()
    if N >= K:
        s = N - K + 1
        n = K
    else:
        s = 0
        n = N + 1
    for d in range(1, n):
        s += 2**(-ceil(log2(K/d)))
    print(s/N)

main()

Solution (Python):
N,K = map(int,input().split())
flag,fin,n = 0,0,0
for i in range(1,N+1):
 n = i
 while n < K:
  n *= 2
  flag += 1
 fin += 1/(N * 2**flag)
 flag = 0
print(fin)

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

Solution (Python):
import math


N, K = map(lambda x: int(x), input().split())
sum = 0

if(N < K):
    edited_N = N
else:
    edited_N = K - 1

for i in range(1, edited_N + 1):
    num = math.ceil(math.log(K/i, 2))
    sum += 0.5 ** num


sum = sum * (1 / N)
if(N >= K):
    sum += (N - edited_N) / N
print(sum)

Solution (Python):
import math
N,K=map(int, input().split())
print(sum(map(lambda x: 0.5**max(0.0, math.ceil(math.log(K/x, 2))), range(1, N+1)))/float(N))

Solution (Python):
n, k = map(int, input().split())
p = 0
for _n in list(range(1,n+1)):
  t = 0
  while (_n * (2**t) < k):
    t = t + 1
  p = p + 1/n * (1/2)**t
print("{}".format(p))

Solution (Python):
import math
data = [int(s) for s in input().split()]
sum = 0
for i in range(1, data[0]+1):
  if i >= data[1]:
    sum += 1/data[0]
  else:
    l = (math.ceil(math.log2(data[1]/i)))
    sum += (1 / data[0]) * (1/2) ** l
print(sum)

Solution (Python):
import math

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

if N >= K:
  odd += (N-K+1)/N
  for i in range(K-1):
    if (math.log2(K/(i+1)))%1==0:
      odd += (i+1)/(K*N)
    else:
      odd += (1/N)*(0.5**(int(math.log2(K/(i+1)))+1))
else:
  for i in range(N):
    if (math.log2(K/(i+1)))%1==0:
      odd += (i+1)/(K*N)
    else:
      odd += (1/N)*(0.5**(int(math.log2(K/(i+1)))+1))
      
print(odd)

Solution (Python):
import math

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

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

for i in range(min(N, K)):
    logk = math.ceil(math.log2(K / (i+1)))
    ans += 1 / N * (0.5 ** logk)

print(ans)

Solution (Python):
import math
n,k = map(int, input().split())
res = float(0)
orig = math.ceil(math.log2(k) )
count = 0
for i in range(1, n+1):
    if i > k:
        count += pow(2,orig)
    else:
        
        t = math.ceil(math.log2(k) - math.log2(i))
        tt = pow(2, orig - t )
        count += tt
res = count / (n*pow(2,orig))
print(res)

Solution (Python):
import math

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

Solution (Python):
N, K = map(int,input().split())
answer = 0
for i in range(N):
  dice = i + 1
  time = 0
  if dice >= K:
    answer += 1/N
    continue
  else:
    while (True):
      dice=dice*2
      time+= 1
      if dice >= K :
        answer += (1/N)*((1/2)**time)
        break
print(answer)

Solution (Python):
N,K=map(int,input().split())
def dice_coin(N,K):
    pro=[]
    for i in range(N):
        count=0
        j=0
        while K-(i+1)*2**j>0:
            j=j+1
        pro.append(1/N*(1/2)**j)
    return sum(pro)
print("{}".format(dice_coin(N,K)))

Solution (Python):

"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime
import re

def howmany_power(n, k):
    if n >= k:
        return 0
    else:
        return howmany_power(n*2, k) + 1


def sol(N, K):
    P = 0
    for n in range(1, N+1):
        if n < K:
            x = howmany_power(n, K)
            tmp = 2**x
            fst = N
            
            P += (1/tmp)*(1/fst)
        else:
            
            P += (1.0/N)
    return P


do_submit = True


def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    
    return n, k


if not do_submit:
    n, k = input_parse("""
    3 10
    """)
    print(sol(n, k))

    n, k = input_parse("""
    100000 5
    """)
    print(sol(n, k))


else:
    n, k = list(map(int, input().split()))
    
    print(sol(n, k))

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


memo = {}
def times(i, count):
    if i in memo:
        return memo[i]
    if i < K: 
        ret  = times(i * 2, count + 1)
    else:
        ret = count
    memo[i] = ret - count
    return ret


ret = 0
for n in range(1, N + 1):
    t = times(n, 0)

    ret += (1/N) * pow((1/2), t)

print(ret)

Solution (Python):
N,K = map(int,input().split())
t = []
j = 0
for i in range(N,0,-1):
    while i * (2**j) < K:
        j += 1
    t.append((i,j))

ansU = 0
ansD = (2**j)*N
for i,n in t:
    ansU += 2**(j-n)
print(round(ansU/ansD,10))

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


def cc(n):
    i = 0
    while True:
        if K <= (n * (2 ** i)):
            return i
        i += 1


A = 0
for n in range(1, N+1):
    A += 1.0 / N * (0.5 ** cc(n))
print(A)

Solution (Python):



C = input().split()
N = int(C[0])
K = int(C[1])

out = 0

for i in range(N):
    l = i + 1

    if l < K:

        d = l
        count = 0

        while d < K:
            d = d * 2
            count += 1
        
        
        

        ans = 1 / N * pow(1/2, count)
        out += ans
    else:
        ans = 1 / N * pow(1/2, 0)
        out += ans




print("{0:.12f}".format(out))

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

x = 2
count = 1
while(True):
    if x < K:
        x = x * 2
        count += 1
    else:
        break

ans = 0

for i in range(1, N+1):

    if 2 ** (count - 1) * i >= K:
        count -= 1
        if count == 0:
            ans += N-i+1
            break

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

Solution (Python):
import math
def AAA(s,k):
    a = 1
    while s*math.pow(2,a) < k:
        a = a+1
    return a
def Coin(n,k):
    s = [i+1 for i in range(n)]     
    b = list(map(lambda a:AAA(a,k) if a<k else 0,s))
    res = list(map(lambda a:(1/n)*math.pow(1/2,a) if a!=0 else 1/n,b))
    return sum(res)
n,k = map(int, input().split())
print(Coin(n,k))

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

result = 0

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

    result += 1/n * ((1/2) ** j)

print(result)

Solution (Python):
import math
from decimal import Decimal

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

win_p = []

for n0 in range(1, n+1):
    if k <= n0:
        win_p.append(1)
        continue
    x = math.ceil(math.log2(Decimal(str(k)) / Decimal(str(n0))))
    win_p.append(Decimal(0.5)**x)

print('{:.9f}'.format(sum(win_p) / n))

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

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

print(ans)

Solution (Python):
import math
N,K=map(int,input().split())
p=[0 for i in range(20)]
for i in range(20):
  M=K
  for j in range(i):
    M=M/2
  p[i]=math.ceil(M)
t=N+1
i=0
A=0
ans=0
while p[i]>N:
  i+=1
while p[i]!=1:
  s=p[i]
  ans+=((t-s)/2**i)/N
  t=s
  i+=1
s=p[i]
ans+=((t-s)/2**i)/N
print(ans)

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

ka = 0

for i in range(1, n+1):
    
    if(i >= k):
        
        
        ka += 1 * (n+1-i)
        break
    
    else:
        j = 1
        while(1):
            if (i * (2 ** j)) >= k:
                break
        
            j += 1
    
        ka += 1 * ((1/2)**j)
        
        
    
    
    
print(ka/n)

Solution (Python):
n,k = map(int,input().split())
score = []
res = 0

for i in range(1,n+1):
    count = 0
    while True:
        if i*2**count < k:
            count += 1
        else:
            score.append(count)
            break

for s in score:
    res += (1/n)*((1/2)**s)

print(res)

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

clist = []
for i in range(1,N+1):
    a = i
    c = 0
    while(a<K):
        a *= 2
        c += 1
    clist.append(c)

import numpy as np
X = np.array(clist)
Y = np.array([0.5]*N)

print(sum(Y**X*(1/N)))

Solution (Python):
n,k=map(int,input().split())
lst=[]
for m in range(1,n+1):
  a=1
  cnt=0
  for i in range(100000):
    if m*a>=k:
      lst.append(cnt)
      break
    else:
      a*=2
      cnt+=1
totl=0
for j in range(n):
  totl+=0.5**lst[j]
print(totl/n)

Solution (Python):
import math
N, K = tuple(map(int, input().split()))
base = 1 / N

if N == K:
  s = base
  end = K
elif N > K:
  s = (N-K+1) / N
  end = K
else:
  s = 0
  end = N+1
for i in range(1, end):
  n = math.ceil(math.log2(K/i))
  s += base * (0.5 ** n)
print(s)

Solution (Python):
import math

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

a = 0

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

Solution (Python):
import math
n, k = [int(i) for i in input().split()]
ans = 0
for ni in range(1, n + 1):
    if ni < k:
        ans += 1 / math.pow(2, math.ceil(math.log2(k / ni)))
    else:
        ans += 1
ans /= n
print(ans)

Solution (Python):
a = input().split()
men = int(a[0])
score = int(a[1])
prob = 0
for i in range(1, men + 1):
  get = i
  count = 0
  while get < score:
    count += 1
    get *= 2
  prob += (1 / men) * ((1/2)**count)

print(prob)

Solution (Python):

N,K =map(int,input().split())
n = 0
ans = 0
L = K-1
R = N
while True:
    if L < N:
        break
    else:
        n += 1
        R = L
        L = R//2

if R > N:
    R=N

while True:
    foo = R-L
    foo /= 2**n
    ans += foo
    if L==1:
        ans += 1/(2**(n+1))
        break
    if L ==0:
        break
    R = L
    L =R//2
    n += 1
print(ans/N)

Solution (Python):

import math

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

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

print(output)

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

Solution (Python):
N, K = map(int,input().split())
L = []

import math

def calc_prob1(n, k):
    return (1/N) * (1/2)**(math.ceil(math.log2(k/n)))

if K == 1:
    print(1.0)
elif N < K:
    for i in range(1,N+1):
        L.append(calc_prob1(i, K))
    print(sum(L))
else:
    for i in range(1, K+1):
        L.append(calc_prob1(i, K))
    L.append((1 - K/N))
    print(sum(L))

Solution (Python):
from decimal import Decimal
N, K = map(int, input().split())


def Cal(N, K):
    if N < K:
        pro = Decimal(0)
        for n in range(1, N+1):
            for j in range(0, K):
                n = n * 2
                if n >= K:
                    break
            pro += (Decimal(1) / Decimal(N * 2**(j+1)))
        return pro
    else:
        pro = Decimal(N-K+1) / Decimal(N)
        for n in range(1, K):
            for j in range(0, K):
                n = n * 2
                if n >= K:
                    break
            pro += (Decimal(1) / Decimal(N * 2**(j+1)))
        return pro


ans = Cal(N, K)
print(ans)

Solution (Python):
import math
N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
      X = K / i
      Y = math.log(X,2)
      if Y * 10 % 10 == 0.0:
        Y_int = int(Y)
      else:
        Y_int = int(Y) + 1
      if i < K:
        Z = 1 / N * (0.5 ** Y_int)
        ans += Z
      else:
        ans += 1 / N

print(ans)

Solution (Python):
import math

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

def calc_p(i, k):
    if k <= i:
        return 0
    return math.ceil(math.log2(k)-math.log2(i))

print(sum([(1/n)*(1/2)**calc_p(i,k) for i in range(1,n+1)]))

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



L = math.ceil(math.log(K,2))


S = 0.0
if N >= K:
	S += (N-K+1)/N
for i in range(L):
	T = math.ceil(K/2**i)
	B = math.ceil(K/2**(i+1))

	if N >= T:
		S += (1/N)*(T-B)/2.0**(i+1)

	elif T > N >=B:
		S += (1/N)*(N+1-B)/2.0**(i+1)

	elif N==B:
		S += (1/N)*(N+1-B)/2.0**(i+1)

print(S)

Solution (Python):

import numpy as np


def solv(n, k):
    d = np.arange(1, n+1, dtype='float64')
    p = np.fmax(k / d, 1)
    t = np.ceil(np.log2(p))
    r = np.power(0.5, t)
    return np.mean(r)


if __name__ == '__main__':

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

    print(ans)

Solution (Python):




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

p = 0



for i in range(N,0,-1):
    if i >= K:
        p += 1/N
    elif K/2 <= i < K:
        p += 1/N/2
    elif K/2**2 <= i < K/2:
        p += 1/N/2**2
    elif K/2**3 <= i < K/2**2:
        p += 1/N/2**3
    elif K/2**4 <= i < K/2**3:
        p += 1/N/2**4
    elif K/2**5 <= i < K/2**4:
        p += 1/N/2**5
    elif K/2**6 <= i < K/2**5:
        p += 1/N/2**6
    elif K/2**7 <= i < K/2**6:
        p += 1/N/2**7
    elif K/2**8 <= i < K/2**7:
        p += 1/N/2**8
    elif K/2**9 <= i < K/2**8:
        p += 1/N/2**9
    elif K/2**10 <= i < K/2**9:
        p += 1/N/2**10
    elif K/2**11 <= i < K/2**10:
        p += 1/N/2**11
    elif K/2**12 <= i < K/2**11:
        p += 1/N/2**12
    elif K/2**13 <= i < K/2**12:
        p += 1/N/2**13
    elif K/2**14 <= i < K/2**13:
        p += 1/N/2**14
    elif K/2**15 <= i < K/2**14:
        p += 1/N/2**15
    elif K/2**16 <= i < K/2**15:
        p += 1/N/2**16
    elif K/2**17 <= i < K/2**16:
        p += 1/N/2**17

print(p)

Solution (Python):
N, K = map(int, input().split())
import math
def deno(x):
    if x >= K:
        return 1
    else:
        count = math.ceil(math.log(K/x, 2))
        return 1 / (2 ** count)
pro = sum(map(deno, range(1,N+1))) / N
print(pro)

Solution (Python):
N, K = map(int, input().split())
k = K
twofac = 2
boarder = []
enough = 0
while(k > twofac):
    if k % twofac == 0:
        boarder.append(k // twofac)
    else:
        boarder.append(k // twofac + 1)
    twofac *= 2
boarder.append(1)
boarder.insert(0, K)
each = 1 / N
ans = 0
lenb = len(boarder)
for i in range(lenb-1, 0, -1):
    if boarder[i-1] <= N:
        ans += (boarder[i-1]-boarder[i])*each/(2**i)
    else:
        ans += (N-boarder[i]+1)*each/(2**i)
        enough = 1
        break
if enough == 0:
    ans += (N-K+1)*each
print(str(ans))

Solution (Python):
n, k = map(int, input().split())
res = 0
tmp = 1
for i in range(n, 0, -1):
  while True:
    if i * tmp >= k:
      res += 1 / tmp
      break
    tmp = tmp * 2
print(res/n)

Solution (Python):
n,k = map(int, input().split())
dice = 1/n
n = list(range(1,n+1))

import math
def cal(i):
  return dice * (1/2)**max(0,math.ceil(math.log2(k/i)))

print(sum([cal(i) for i in n]))

Solution (Python):
N, K = list(map(int, input().split()))
ans = 0
koe = False
for i in range(N):
    a = i + 1
    if a > K-1:
        koe = True
        break
    flag = True
    count = 0
    while flag:
        a = a * 2 
        count = count + 1
        if (a >= K):
            flag = False
    ans += 1/N * (1/2)**count
if koe:
    ans += (N-(K-1))/N
print(ans)

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

Solution (Python):
def main():
	N, K = map(int, input().split())
	dp = [0 for _ in range(K+1)]

	if K > N:
		for i in range(1, N+1):
			dp[i] = 1
	else:
		for i in range(1, K):
			dp[i] = 1
		dp[K] += (N-K+1)
	ans = dp[K]
	for i in range(1, min(N+1, K)):
		cur = i
		this_p = dp[i]
		while cur < K:
			this_p *= 0.5
			cur *= 2
		ans += this_p
	print(ans/N)

if __name__ == '__main__':
	main()

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

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

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

for i in range(1,min(k,n+1)):
    if math.log(k/i,2)-int(math.log(k/i,2))== 0:
        p = int(math.log(k/i,2))
    else:
        p = int(math.log(k/i,2))+1
    ans +=(1/n)*(0.5**p)
print(ans)

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

def afterdiceprob(x):
    flag = True
    y = 0
    while(flag):
        if x*2**y >= K:
            break
        y += 1
    return y

sum = 0
kmax = 0
for k in range(1,N+1):
    sum += (1/N)*(1/2)**afterdiceprob(k)
print(sum)

Solution (Python):
import math
n,k=map(int,input().split())
ans=0

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

Solution (Python):
import math
from decimal import Decimal
N, K = [int(item) for item in input().split()]
b = 0
for i in range(1, N+1):
  tmp = i
  cnt = 0
  while tmp < K:
    tmp *= 2
    cnt += 1
  if i == 1:
    a = (N * 2 ** cnt)
  b += (a / (N * 2 ** cnt))
print(Decimal(b/ a))

Solution (Python):
nk = list(map(lambda x: int(x), input().split()))
n = nk[0]
k = nk[1]

poss_points = [i+1 for i in range(n)]
needed_wins = [-1 for i in range(n)]

def convert(x):
  if (x == -1):
    return 0
  else:
    return x

def calc(x):
  return (1/n) * 0.5 ** x

for i in range(n):
  times = 0
  point = poss_points[i]
  if (needed_wins[i] != -1):
    continue

  while(True):
    if (point >= k):
      break
    point = point * 2
    times += 1

  if (times == 0):
    break
    
  next_int = i + 1
  while(times > 0 and next_int <= n):
    needed_wins[next_int-1] = times
    next_int = next_int * 2
    times -= 1


needed_wins = list(map(convert, needed_wins))

array = list(map(calc, needed_wins))
answer = sum(array)

print(answer)

Solution (Python):
n,k=map(int, input().split())
p=0
import math
for i in range(1, n+1):
    if i < k/2:
        pi = math.ceil(math.log2(k/i))
        p += (1/n)*((0.5)**pi)
    elif i >= (k/2) and i < k:
        p += (1/n)*0.5
    else:
        p+= 1/n 

print(p)

Solution (Python):
import sys
input = sys.stdin.readline

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


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

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

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

for i in range(N):
    coin_num = math.log(K/(i+1)) / math.log(2)
    if K > (i+1) :
        if int(coin_num) == coin_num:
            pass
        else:
            coin_num = int(coin_num) + 1
        possibility += (1/N) * ((1/2) ** int(coin_num))
    else:
        possibility += (1/N)

print(possibility)

Solution (Python):
import numpy as np
N,K = map(int,input().split())
ans = np.full(N,1/N)
ans_2 = np.array(range(N))
ans_2 += 1
prob = 0
for i in range(N):
	if ans_2[N-i-1] >= K:
		prob += ans[N-i-1]
	else:
		while ans_2[N-i-1] < K:
			ans_2 *= 2
			ans *= 1/2
		prob += ans[N-i-1]
print(prob)

Solution (Python):
import math
N, K = map(int, input().split())
results = []
for i in range(N+1)[1:]:
  s = -(-K // i)
  r = math.ceil(math.log2(s))
  results.append(1.0/float(N*(2**r)))
print(sum(results))

Solution (Python):
n, k = input().strip().split()
n, k = [int(n), int(k)]
ans = 0
for i in range(n):
  ii = i + 1
  temp = ii
  x    = 0
  while ( temp < k ):
    temp *= 2
    x += 1
  
  ans += 1 / ( (2**x) * n )
  
print (ans)

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

win_prob = 0

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

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

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

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

def twice(now, cnt):
    
    if now >= k:
        return cnt
    cnt += 1
    return twice(now * 2, cnt)

if __name__ == '__main__':
    ans = 0
    for i in range(1, n+1):
        cnt = 0
        
        
        
        ans += float(1/n) * float((1/2)**int(twice(i, cnt)))
    print(ans)

Solution (Python):
N, K = map(int, input().split())
seq = [-1]*N
pos=N
kei = 1
count = 0
result = 0
for i in reversed(range(N)):
    while K>(i+1)*kei:
        kei*=2
        count+=1
    result += 1/kei
print(result/N)

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

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

print(p)

Solution (Python):
n, k = map(int, input().split())
pow = [0 for _ in range(n)]
l, r = n-1, 0
while l >= 0:
    while (l+1) * 2**r < k:
        r += 1
    pow[l] = r
    l -= 1
ans = 0
for i in range(n):
    ans += 1/n * 0.5**pow[i]
print(ans)

Solution (Python):
N,K = map(int,input().split())
t = 1/N
a = []
X = K
i = 0
for i in range(20):
  if X%2 == 0:
    for j in range(int(X/2)):
      a.append(0.5**(i+1))
    X = X/2
    i += 1
  else:
    for j in range(int((X-1)/2)):
      a.append(0.5**(i+1))
    X = (X+1)/2
    i += 1
if K>N:
  ans = sum(a[K-N-1:])*t
elif K == N:
  ans = (sum(a)+1)*t
else:
  ans = (sum(a)+(N-K+1))*t
print(ans)

Solution (Python):
from fractions import Fraction
x, y = list(map(int, input().split(' ')))

ls = []
for start in range(1, x + 1):
    if start < y:
        tmp = start
        turns = 0
        while tmp < y:
            tmp *= 2
            turns += 1

        f1 = Fraction(1, pow(2, turns))        
        ls.append(f1)

t = Fraction(0, 1)
for num in ls:
    t += num

t += Fraction(max(x - y + 1, 0), 1)

print(float(t) / x)

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

ans = 0

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

ans = ans * 1.0/n

print(ans)

Solution (Python):

import sys
import decimal
input = sys.stdin.readline
decimal.getcontext().prec = 13
dec = decimal.Decimal

s = input().split(" ")
d = int(s[0])
k = int(s[1])

sums = 0
for i in range(d):
    x = i + 1
    j = 0
    while x < k: 
        x = x * 2
        j = j+1
    sums = sums + dec(1)/dec(d) * (dec(1) /dec(2) ** dec(j))

print(sums)

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

def count(i,K):
    sum = 0
    cnt = 0
    while sum < K:
        if cnt == 0:
            sum = i*2
            cnt += 1
        else:
            sum = sum*2
            cnt += 1
    return cnt

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

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

print(prob)

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

for i in range(N):
  point = i+1
  t_ans = 1/N
  while point >= 1 and point <= K-1:
    point = point * 2
    t_ans = t_ans / 2
  ans += t_ans

print(ans)

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

ans = 0

for i in range(1,N+1):
    a = math.ceil(math.log2(K/i))
    ans += 1/(N*(2**a))
    if i >= K:
        ans += (N-K)/N
        break

print(ans)

Solution (Python):
l = input().split()
N = int(l[0])
K = int(l[1])
P = 0
for i in range(1,N+1):
    score = i 
    times = K / score
    j = 0
    while times > 1 :    
        times = times / 2
        j += 1
    p = 1/N * ((1/2)**j)
    P += p
print(P)

Solution (Python):


from sys import stdin
import random

N,K = list(map(int, stdin.readline().split()))

result = 0

for n in range(N):
    n = n + 1
    x = 0
    while True:
        if 2 ** x * n >= K:
            break
        x += 1
    result += 1/N * 0.5 ** x

print(result)

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

Solution (Python):
import math

N, K = map(int, input().split())
ans = 0
for m in range(1, N+1):
    x = math.log2(K / m)
    if x - int(x) > 0:
        x += 1
    if x > 1:
        ans += (1/2) ** int(x) / N
    else:
        ans += 1 / N
print(ans)

Solution (Python):



import numpy as np

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

x = np.arange(N) + 1
c = np.ceil(np.log2(K / x)).astype(int)
c = c[np.where(c > 0)]
if len(c) == 0:
    print(1)
else:
    cumprod = np.cumprod([0.5] * int(c[0]+1))
    print(2 * np.sum(cumprod[c]) / N + (N - len(c)) / N)

Solution (Python):
N,K=list(map(int,input().strip().split(' ')))

prob=0
for i in range(1,N+1):
    if i>=K:
        prob+=(N-K+1)/N
        break
    power=0
    for j in range(20):
        if i*(2**j)>=K:
            power=j
            break
    prob+=(1/N)*(1/2)**power

print(prob)

Solution (Python):
N, K = [int(i) for i in input().split()]
sum = 0
float(sum)
for i in range(1, N + 1):
    b = i
    con = 0
    while K > b:
        b = b * 2
        con += 1
    else:
        sum += 1 / N * (0.5 ** con)

print(sum)

Solution (Python):


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

Solution (Python):
import math

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

sum = 0
for i in range(n):
    coin = math.ceil(math.log2(k / (i + 1)))
    if coin > 0:
        sum = sum + 0.5 ** coin
    else:
        sum = sum + 1

print(sum / n)

Solution (Python):

if __name__ == '__main__':
    n,k = list(map(int, input().split()))
    n2 = n
    count = 1
    kakuritu = 0

    while(n2 != 0):

        ktop = int(n2 - k + 1)
        if(ktop > 0):
            kakuritu += ktop / n * 1 / count
            n2 -= ktop

        k /= 2
        count *= 2
        
    print(kakuritu)

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

from fractions import Fraction

probability = Fraction(1, N)
probability_total = 0

for i in range(N):
    count = 0
    point = i + 1
    while K > point:
        count += 1
        point = point * 2
    probability_total = probability_total + probability * Fraction(1, 2) ** count

print(float(probability_total))

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

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

    ans += 1/float(N) * 0.5**c
print(ans)

Solution (Python):
men, kazu = map(int,  input().split())

ans = 0

for i in range(men):
    ansKazu = i + 1
    kaisuu = 0
    while ansKazu < kazu:
        ansKazu = ansKazu * 2
        kaisuu = kaisuu + 1

    prob = 1/men * ((1/2) ** kaisuu)
    ans = ans + prob

print(ans)

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

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

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

p = p / n
print(p)

Solution (Python):
import math

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

p = 0
N_inv = 1.0/N

for ii in range(1,N+1):
    if K > ii:
        
        exp_n = math.ceil(math.log(K/ii,2))
        p = p + N_inv * (0.5)**exp_n
        
    else:
        p = p + N_inv
        

print(p)

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

nij = []

for i in range(K):
    if 2 ** (i+1) >= K * 4:
        break
    nij.append(2 ** i )
    
ans = 0
cur = len(nij)-1

for i in range(N):
    for j in range(len(nij)):
        
        if nij[cur-j]*(i+1) >= K and nij[cur-j-1]*(i+1) < K:
            
            ans = ans + 1 / N * 0.5 ** (cur-j)
            
            break
            
        elif (i+1) >= K:
            ans = ans + 1 / N
            
            break

print(ans)

Solution (Python):

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

def countZero(f):
    if f >= 0:
        return -1
    s = '{:.11f}'.format(f)
    if s.find('.') < 0:
        return -1

    n = s.split('.')[1]
    ss = str(n)
    count = 0
    for i in range(len(ss)):
        if ss[i] == '0':
            count +=1
        else:
            break
    return count
    
prob = 0
for i in range(N):
    n = N - i
    n2 = n
    count = 0
    while True:
        if n2 >=K:
            break
        count+=1
        n2 = n2*2

    ans = (1/N) * pow(0.5, count)
    if countZero(ans) >= 11:
        break
    else:
        prob += ans

print(prob)

Solution (Python):


''' 
------------------------
author : iiou16
------------------------
'''

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

    p = [1 / N] * N

    for i in range(1, N+1):
        count = 2
        point = i
        while point < K:
            p[i-1] *= 0.5
            point = point * count
        
    print(sum(p))


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
import math

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

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