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 os, sys, re, math

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

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

print(ret / n)

Solution (Python):
n, k = map(int, input().split())
ans = 0
for x in range(1, n + 1):
    tmp = x
    count = 0
    while True:
        if tmp >= k:
            break
        tmp *= 2
        count += 1
    if x < k:
        ans += (1 / n) * ((1 / 2)**count)
    else:
        ans += (1/n)
    count -= 1

print(ans)

Solution (Python):
import math

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

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

a = len(bin(K))-2
c = 0


prob1 = min(1,(K-1)/N)
prob2 = 1-prob1

cnt = 0
ans = 0
while (K-1)//(2**cnt) > 0:
    
    n = min(N, (K-1)//(2**cnt)) - (K-1)//(2**(cnt+1))
    if n > 0:
       ans += n*1.00/(N*2**(cnt+1))
    
    cnt+=1
    
print(ans+prob2)

Solution (Python):
import math

inputs = input().split()
n = int(inputs[0])
k = int(inputs[1])

p = [0] * n
for dice in range(n):
    p[dice] = 1/n
    point = (dice+1)
    while point < k:
        p[dice] *= 1/2
        point *= 2.0

print(sum(p))

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]









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

Solution (Python):
import math

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

lst = [1]
K2 = 1
while K2 < K:
    K2 *= 2
    lst.append(K2)

cnt = 0
for i in range(1,N+1):
    now = math.ceil(K/i)
    if now == 1:
            cnt += lst[-1]
    else:
         for j in range(len(lst)-1):
            if lst[j] < now <= lst[j+1]:
                cnt += lst[-1] // lst[j+1]

ans = cnt / (N * lst[-1])
print(ans)

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

Solution (Python):



import math

def main():
    n, k = list(map(int, input().split()))
    cand = []
    tk = k
    tn = n
    while tk > 0.5:
        if int(tk) == tk:
            cand.append(max(0, tn-tk+1))
            tn = min(tn, tk-1)
        else:
            cand.append(max(0, tn-int(tk)))
            tn = min(tn, int(tk))
        tk /= 2
    ans = sum(cand[i] * pow(2, len(cand)-i) for i in range(len(cand)))
    print(ans/(n*pow(2, len(cand))))


if __name__ == '__main__':
    main()

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

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

a = k
for i in range(1, 18):
    b = -(-a // 2)
    if b <= n:
        ans += min(a - b, n + 1 - b) / n * (0.5) ** i
    a = b
print(ans)

Solution (Python):
import sys
import math

def solve(n, k):
    ans = 0.
    rate = 1./n
    for i in xrange(n):
        if i + 1 >= k:
            ans += rate
        else:
            ans += rate * 0.5 ** math.ceil(math.log(k/(i+1), 2))

    return ans

if __name__ == '__main__':

    n, k = sys.stdin.readline().strip().split(" ")
    print solve(int(n), float(k))

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

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

sum = 0
x = 0
for i in range(n,0,-1):
    while i * (2 ** x) < k:
        x += 1
    if (i * (2 ** x) > k * 2) and x >= 1:
        x -= 1
    sum += (1/2)**x / n

print(sum)

Solution (Python):
import math

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

ans = 0.0

for i in range(N):
    if i+1 > K:
        ans += 1.0/N
        continue
    else:
        x = math.log2(K/(i+1))
        x = math.ceil(x)
        ans += math.pow(0.5, x) * (1.0/N)

print("{:.10f}".format(ans))

Solution (Python):
N,K=map(int,input().split())
s=0
for n in range(N):
    score=n+1
    cnt=0
    while score<K:
        score*=2
        cnt+=1
    e=1/N*(1/2)**cnt
    if score >=K:
        s+=e
print(s)

Solution (Python):



def main():
	n, k = map(int, input().split())

	ans = 0
	tmp = 1/n

	for i in range(1, n+1):
		if i >= k:
			ans += tmp
			continue
		count = 0
		num = i
		while True:
			num *= 2
			count += 1
			if num >= k:
				ans += tmp * pow(0.5, count)
				break

	print(ans)



if __name__ == '__main__':
	import sys
	sys.exit(main())

Solution (Python):
import math

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

Solution (Python):


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

winrate = 0.0


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


winrate = winrate/n


print winrate

Solution (Python):

N,K=map(int,input().split())
k=K
p=[0]*20
p[0]=10**5+1
for i in range(19):
    p[i+1]=k
    k=k/2

ans=0
for i in range(N):
    for j in range(19):
        if i+1<p[j] and i+1>=p[j+1]:
            ans+=(1/N)*((1/2)**(j))
print(ans)

Solution (Python):
N, K = map(int, input().split())
ans = 0
for n in range(1, N+1):
    if n >= K:
        ans += 1 / N
    else:
        L = 1
        V = n * 2
        while V < K:
            V *= 2
            L += 1
        ans += 0.5 ** L / N
print(ans)

Solution (Python):
import math

[N,K]=[int(i) for i in input().split()]

tsum=0

for x in range(1,N+1):
	
	logarithm=max(math.ceil(math.log(K/x,2)),0)
	
	tsum+=(1/(N*pow(2,logarithm)))

print(tsum)

Solution (Python):
from math import log

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

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

print(sum_num / N)

Solution (Python):
import math

n,k = map(int,input().split())
ans = 0
pre_ans = 0
for i in range(1,n+1):
    twoNum = 1
    score = i
    while score < k:
        score *= 2
        twoNum *= 2
    ans += twoNum**-1 / n
print(round(ans,12))

Solution (Python):
import math
N,K = map(int,input().split())
ite = []
for n in range(1,N+1):
  num = int(math.ceil(math.log2(K/n)))
  if num > -1:
    ite.append(num)
  else:
    ite.append(0)
ans = []
for i in ite:
  ans.append((1/N)*(0.5)**i)
print(sum(ans))

Solution (Python):


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

counts = []

for i in range(1, n+1):
    a = i
    count = 0
    while a < k:
        a *= 2
        count += 1
    counts.append(count)

result = 0


for count in counts:
    result += (1 / n ) * ((0.5) ** count)

print(result)

Solution (Python):
import math
N, K = map(int, input().split())
p = 0
for n in range(1,N+1):
	if n >= K : p+= 1/N
	else:
		c = max(1, math.ceil(math.log(K/n,2)))
		p += ((1/2)**c)/N
print(p)

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

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

print(ans/N)

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

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

for i in range(1,N+1):
  if i >= K:
    ans=ans+1.0/N
    continue;
    
  hi=100
  lo=0
  while hi-lo>1:
    mid=(hi+lo)//2
    if i*(2**mid)>=K:
      hi=mid
    else:
      lo=mid
    
  ans=ans+1.0/N*(0.5**hi)
  
print(ans)

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

for i in range(n):
    if i+1 >= k :
        kakuritu += 1/n
    elif i+1 < k:
        a=1
        while float(k) - (i+1)*pow(2,a) > 0:
            a += 1
        kakuritu += (1/n) * pow(1/2,a)
print(kakuritu)

Solution (Python):
n,k = (int(i) for i in input().split())
cont = 1/n
ans = 0
for i in range(1,n+1):
    tmp = i
    a_tmp = 0
    while tmp < k:
        a_tmp+=1
        tmp*=2
    ans += cont*(0.5**a_tmp)
print(ans)

Solution (Python):
import math
N, K = map(int, input().split())
ans = 0
deno = 0
for i in range(1, N + 1):
    tmp = i
    cnt = 0
    while tmp < K:
        tmp = tmp * 2
        cnt += 1
    deno += math.pow(1 / 2, cnt)
ans = 1 / N * deno
print(ans)

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

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

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

print(ans)

Solution (Python):
n,k=map(int,input().split())
cal=0
for i in range(1,n+1):
  for j in range(1,20):
    if i>=k:
      cal+=1
      break
    elif i*2**(j-1)<k and i*2**j>=k:
      cal+=(1/2)**(j)
      break
print(cal/n)

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

def f(n):
	count = 0
	while n * (2 ** count) < K:
		count += 1
	return count

P = 0
for n in range(1, N+1):
	P += ( 0.5 ** f(n) ) / N


print(P)

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

Solution (Python):
N, K = map(int, input().split())
coin_num_list = []
if N != K:
    for i in range(1, min(K, N+1)):
        dice_val = i
        j = 0
        while dice_val < K:
            dice_val *= 2
            j += 1
        coin_num_list.append(j)
else:
    for i in range(1, K):
        dice_val = i
        j = 0
        while dice_val < K:
            dice_val *= 2
            j += 1
        coin_num_list.append(j)
pro_sum = 0
for coin_val in coin_num_list:
    pro_sum += (1/2)**coin_val
if N >= K:
    print((N-K+1)/N + pro_sum/N)
else:
    print(pro_sum/N)

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

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

Solution (Python):
n,k = map(int,input().split())
ans = 0
def log2(x):
    c=0
    while(x<k):
        x *=2
        c += 1
    return c
for i in range(1,n+1):
    ans += (1/n)*((1/2)**(log2(i)))
print(ans)

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




p = max(0, (n - k + 1))

for x in range(1, min(n + 1, k)):
    m = 0
    y = x
    while True:
        y = y * 2
        m = m + 1
        if y >= k:
            break
    p += ((1 / 2) ** m)

print(p / n)

Solution (Python):
import math

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

total = 0
for i in range(n, 0, -1):
    
    cnt = 0
    temp = i
    while temp < k:
        temp *= 2
        cnt += 1
    
    power = math.pow(2, -cnt) / n
    total += power
    

print(total)

Solution (Python):
import math
from decimal import *


def read():
    N, K = list(map(int, input().strip().split()))
    return N, K


def solve(N, K):
    
    getcontext().prec = 10
    prob = []
    for n in range(1, N+1):
        x = max(0, math.ceil(math.log2(K / n)))
        prob.append(Decimal.from_float(0.5) ** Decimal(x))
    return sum(prob) / Decimal(N)


if __name__ == '__main__':
    inputs = read()
    print("%.10f" % solve(*inputs))

Solution (Python):
import math

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

print(ans)

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

sum_rate = 0

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

    sum_rate += rate

print(sum_rate)

Solution (Python):
import math

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

if n >= k:
    base = float(n - k + 1) / float(n)
else:
    base = 0

sum = base

for i in range(1, min(k, n + 1)):
    l = math.ceil(math.log(float(k) / float(i), 2))
    
    sum += (1.0 / float(n)) * (0.5 ** l)

print(sum)

Solution (Python):
n, k = map(int, input().split())
ans1 = 0
for i in range(1,n+1):
    num = 0
    while i < k:
        i *= 2
        num += 1
    ans0 = (1/n) * (1/2)**num
    ans1 += ans0
print(ans1)

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

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

Solution (Python):
from collections import Counter
T = Counter()
N, K = map(int, input().split())
for i in range(1, N+1):
    T[(-1-(-K//i)).bit_length()] += 1
ans = 0
for k, v in T.items():
    ans += v*(1/2)**k
print(ans/N)

Solution (Python):
def main():
    n, k = list(map(int, input().split()))
    expect = 0
    for x in range(1, n + 1):
        if x > k - 1:
            expect += 1 / n
            continue
        n2w = 1
        for j in range(1, 100000):
            if x * (2**j) >= k:
                n2w = j
                break
        
        expect += (1 / n) * ((1 / 2) ** n2w)

    print(expect)


main()

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


def calc(ini):
    l = math.ceil(math.log2(K/ini))
    return 0.5**l


ans = 0
for i in range(1, N+1):
    if i >= K:
        ans += 1/N
    else:
        ans += calc(i)/N

print(ans)

Solution (Python):
line = input().split()

n = int(line[0])
k = int(line[1])

sum_p = 0
for i in range(n):
    score = i + 1
    p = 1 / n
    count = 0
    while score <= k - 1:
        score *= 2
        p /= 2
        count += 1
    sum_p += p
    
print('{:.12f}'.format(sum_p))

Solution (Python):
import math

n, k = map(int, input().split())
a = 0
for i in range(1, n + 1):
  t = int(math.ceil(math.log2(k / i)))
  t = 0 if t < 0 else t
  a += 0.5 ** t
  
print(a / n)

Solution (Python):



import math


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


bl = list()
for i in range(18):
    bl.append(2 ** i)


ans = 0
for i in range(1, n + 1):

    for j in range(18):
        wval = i * bl[j]
        if wval >= k:
            break
    ans += (1 / n) * (1 / bl[j])


print(ans)

Solution (Python):
import sys
import math

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

first = float(0)
if N >= K:
    first = float((N - K + 1)/N)

second = float(0)
if N >= K:
    for i in range(1, N+1):
        if i == K:
            break
        temp = float(math.log(K/i, 2))
        second += float(math.pow(1/2, math.ceil(temp)) * (1/N))
else:
    for i in range(1, N+1):
        temp = float(math.log(K/i, 2))
        second += float(math.pow(1/2, math.ceil(temp)) * (1/N))

ans = float(first + second)
print(ans)

Solution (Python):
from decimal import *
n,k = list(map(int,input().split()))
ans = Decimal(0)
if n > k-1:
    ans += Decimal((n-k+1)/n)
    for i in range(k-1):
        score = i+1
        cnt = 0
        while score <= k-1:
            score *= 2
            cnt += 1
        ans += Decimal((0.5**cnt)/n)
    print(ans)
else:
    for i in range(n):
        score = i+1
        cnt = 0
        while score <= k-1:
            score *= 2
            cnt += 1
        ans += Decimal((0.5**cnt)/n)
    print(ans)

Solution (Python):
n, k = map(float, input().split())
ans = 0.0
for i in range(1,int(n)+1):
    count = 0
    tmp = i
    while tmp < k:
        count += 1
        tmp *= 2
    ans += 1/n * (0.5**count)

print(ans)

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


def min_v(x, k):
    v=1.0
    while v>x/k:
        v /= 2
    return v

V = 0
for n in range(1, N+1):
    V += min_v(n, K)

print('{:.16f}'.format(V/N))

Solution (Python):



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

p = []
for i in range(n):
    i = i+1
    if i>=k:
        p.append(1/n)
    else:
        
        cnt = 0
        doubled_i = i
        while doubled_i<k:
            doubled_i *= 2
            cnt += 1
        p.append(1/n * 1/(2**cnt))

print(sum(p))

Solution (Python):

import sys
import math

def solve(N: int, K: int):
    ans = .0
    for i in range(1,N+1):
        if(i <= K):
            t = math.ceil(math.log2(K/i))
            ans += (1/N) * (1/2) ** t
        else:
            ans += 1/N

    print(ans)
    
    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))  
    K = int(next(tokens))  
    solve(N, K)

if __name__ == '__main__':
    main()

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

Solution (Python):
num=[]
num=[int(i) for i in input().split()]
kakuritu_arr = []

i = 1
while i <= num[0]:
    x = i
    y = 0
    while True:
        if x >= num[1]:
            break
        x = x * 2
        y += 1
    kakuritu_arr.append((1/num[0]) * (1/2) ** y)
    i +=1

result = 0
for temp in kakuritu_arr:
    result += temp
print(result)

Solution (Python):
import math

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

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

print(ans)

Solution (Python):
from fractions import Fraction

n, k = map(int, input().split())
r = Fraction(0, 1)

for i in range(n):
    m = i + 1
    l = 1
    while m < k:
        m *= 2
        l *= 2
    r += Fraction(1, l)

print(float(r * Fraction(1, n)))

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

Solution (Python):
import math

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

p = (N-(K-1)) / N
if p < 0:
    p = 0
k = K
single_p = 1 / 2

while k >= 1:
    half = k / 2
    case = min(math.ceil(k), N+1) - math.ceil(half)
    
    if case > 0:
        p += case / N * single_p
    single_p /= 2
    k /= 2

print(p)

Solution (Python):
from decimal import *

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

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

win=Decimal(0)
base_k=Decimal(1)/Decimal(n)
for i in range(1,n+1):
  if i < k:
    beki=count_beki(i,k)
    unq_k=(Decimal(1)/Decimal(2))**beki
    win+=base_k*unq_k
  else:
    win+=base_k

print(round(win,12))

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

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

p = 0

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

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

x = 0
t = 1
while x < K:
    x = N * (2 ** t)
    t += 1
t -= 1
per = 0
if N >= K:
    per += (1.0 / N)
else:
    per += (1.0 / N) * (0.5 ** t)

for i in range(1, N):
    v = N - i
    x = v * (2 ** t)
    while x < K:
        t += 1
        x = v * (2 ** t)
    if v >= K:
        per += (1.0 / N)
    else:
        per += (1.0 / N) * (0.5 ** t)
print(per)

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

Solution (Python):
import math


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

prob = 0

for dice in range(1, n+1):
	if dice >= k:
		prob += 1/n 
	else:
		prob += (1/n) * (1 / math.pow(2, (math.ceil(math.log2(k / dice)))))
		
print(prob)

Solution (Python):
import numpy as np
import math

def coin_prob(dice, score):
    num = math.ceil(np.log2(score/dice))
    return 1/(2 ** num)

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

if N >= K:
    base = (N - K + 1)/N
    for i in range(1,K):
        base = base + coin_prob(i, K)/N
else:
    for i in range (1,N + 1):
        base = base + coin_prob(i, K)/N
print(base)

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

for n in range(N, 0, -1):
    
    while 2**t < K / n:
        t += 1
    inv_ans += 1 / 2**t

print(inv_ans / N)

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

ans=0
l=1
r=0
for z in range(1,N+1):
  l=0
  p=z
  while True:
    if p>=K:
      break
    p*=2
    l+=1
  if l==0:
    f=N
    
    
  else:
    f=N*2**l

  ans+=1/f

ans+=r

print(ans)

Solution (Python):
import sys
import math 
import numpy as np
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N,K=na()
n=N
k=10**9
cnt=0
if(N==1):
    if(K==1):
        print(1)
        exit()
    else:
        ans=0
        while(N<K):
            ans+=1
            N*=2
            
        print(0.5**ans)
        exit()
while(N<K):
    
    K=math.ceil(K/2)
    cnt+=1
k=K

ans=0
first=True
while(True):
    if(first):
        ans+=(N-k+1)*(0.5**cnt)
        first=False
    else:
        ans+=(N-k)*(0.5**cnt)

    
    
    cnt+=1
    N=k
    k=math.ceil(k/2)
    
    if(k==1):
        ans+=1*(0.5**cnt)
        
        
        break

ans=ans/n
print(ans)

Solution (Python):
import math
from math import log2
from math import ceil

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

def prob_wins(x,k):
    if x>=k:
        return 1
    return 0.5**ceil(log2(k/x))

ans = 0
for i in range(1,N+1):
    ans += prob_wins(i,K)
    
print(ans/N)

Solution (Python):





import sys
input = sys.stdin.readline
N, K = map(int, input().split())





import math









sum_ = 0
R = min(N, K)
clear = N-K+1 if N>=K else 0
R = R-1 if N>=K else R

for i in range(R):
    
    sum_ += (1/2) ** math.ceil(math.log(K/(i+1), 2))





print(round(1/N*sum_ + clear/N, 16))

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

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

P = 0
for i in range(N):
    i += 1
    c = 0
    while i <= K-1:
        i *= 2
        c += 1
    P += (0.5**c)/N

print(P)

Solution (Python):
import math

n, k = map(int,input().split())
log_k = math.log2(k)
p = 0

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

print(p)

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



ans = 0


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



print(ans/N)

Solution (Python):
import numpy as np

N, K = [int(x) for x in input().split()]

L = np.arange(N)
L += 1

count = np.sum(L >= K)
times = 1

prob = times * count

while count < N:
  times += 1
  old_count = count
  L *= 2
  count = np.sum(L >= K)
  prob += (count - old_count)*(0.5)**(times-1)
prob /= N
print(prob)

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

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

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

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

for n in range(1,N+1) :
    if n >= K :
        total += 1.0 / N
    else :
        total += (1.0 / N) * 0.5 ** math.ceil(math.log2(1.0 * K / n))
print(total)

Solution (Python):
n,k=[int(i) for i in input().split()]
ans=0
hoge=1
while hoge<k:
    hoge*=2
for i in range(1,n+1):
    while i*hoge//2>=k:
        if hoge==1.0:
            break
        hoge/=2
    ans+=(1/n)*(1/hoge)
    
print(ans)

Solution (Python):
from math import ceil, log
n, k = map(int, input().split())
if n > k:
    ans = (n-k)/n
    o = k
else:
    ans = 0
    o = n

for i in range(1, o+1):
    ans += 1 / (n * 2 ** ceil(log(k/i, 2)))
print(ans)

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

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

    while K > i:
        i *= 2
        cnt += 1

    if cnt == 0:
        ans += 1
    else:
        ans += 1/(2**cnt)

print(ans/N)

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



a=decimal.Decimal(0)

for i in range(n):
  if i>=k:
    a+=1
  else:
    a+=(decimal.Decimal(1/2)**abs(math.floor(math.log2((i+1)/k))))
print(a/n)

Solution (Python):
import math
N,K = map(int,input().split())
list2 = [1]
tmp = 1
while tmp < 10 ** 5 + 1:
    tmp *= 2
    list2 += [tmp]

L2 = len(list2)
ans = 0
for i in range(1,N+1):
    tmp = math.ceil(K/i)
    
    for j in range(L2):
        if tmp <= list2[j]:
            break
    ans += list2[j] ** (-1)
ans /= N
print(ans)

Solution (Python):
a = [int(s) for s in input().split(' ')]

i = 0
foo = 0.0

arr = []

for n in range(a[0]):
    x = a[0] - n
    while (x * 2 ** i < a[1]):
        i += 1
    arr.append(i)

for i in arr:
    foo += 0.5 ** i

result = foo * (1 / a[0])

print(result)

Solution (Python):
import math



def win_p(number, k):
    if number > k - 1:
        return 1
    if number == 0:
        return 0
    log_n = math.log((k/number), 2)
    int_log = int(log_n)
    if int_log < log_n:
        int_log += 1
    return math.pow(0.5, int_log)


inp = input()
st_sp = inp.split()
n = int(st_sp[0])
k = int(st_sp[1])
sum_p = 0.0
for i in range(n):
    sum_p += win_p(i+1, k)
print(sum_p/n)

Solution (Python):
import math
N, K = map(int, input().split())
x = 0
for i in range(1, N + 1, 1):
	a = math.ceil(math.log(float(K) / i, 2))
	if a < 0:
		a = 0
	x += float(1) / (2 ** a)
print(float(x) / N)

Solution (Python):
N,K=map(int, input().split())
ans = 0.0
for i in range(1,N+1):
  Z = 0
  S = i
  while True:
    if K <= S:
      break
    Z += 1
    S = S * 2
  ans += (1.0 / N) * pow(0.5, Z)
print(ans)

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

flag = True
check = []
a = 1
while flag:
    check.append(a)
    a *= 2
    if a >= 10 ** 5:
        flag = False
        
ans = 0
for i in range(1, N+1):
    count = 0
    for j in check:
        if j * i >= K:
            break
        count += 1
    ans += 1 / N * 0.5 ** count
print(round(ans, 12))

Solution (Python):

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

prop = 0.0
_prop = 0.0

if n >= k:
    _prop = (n - k) / n

end = min(n, k) + 1
for i in range(1, end):
    dest = k / i
    coin = math.ceil(math.log2(dest))
    __prop = (1 / n) * (1 / pow(2, coin))
    prop += __prop

print(prop + _prop)

Solution (Python):
import sys
import math 
import numpy as np
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N,K=na()
n=N
k=10**9
cnt=0
if(N==1):
    if(K==1):
        print(1)
        exit()
    else:
        ans=0
        while(N<K):
            ans+=1
            N*=2
            
        print(0.5**ans)
        exit()
while(N<K):
    
    K=math.ceil(K/2)
    cnt+=1
k=K

ans=0
first=True
while(True):
    if(first):
        ans+=(N-k+1)*(0.5**cnt)
        first=False
    else:
        ans+=(N-k)*(0.5**cnt)

    
    
    cnt+=1
    N=k
    k=math.ceil(k/2)
    
    if(k==1):
        ans+=1*(0.5**cnt)
        
        
        break

ans=ans/n
print(ans)

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

Solution (Python):

import re
import bisect
from datetime import datetime as dt
import math
n, k = map(int, raw_input().split())
X = []
i = 1
while i <= n:
    x = max(math.ceil(math.log((float(k) / float(i)), 2)), 0)
    X.append(2 ** (-int(x)))
    i += 1
print sum(X) * n ** (-1)

Solution (Python):
import math
from fractions import Fraction
n,k=map(int,input().split())
if n>=k:
	result = (n-k+1)/n
else:
	result = 0
for i in range(1,min(n+1,k)):
	if math.log(k/i,2)==int(math.log(k/i,2)):
		time = int(math.log(k/i,2))
	else:
		time = int(math.log(k/i,2))+1
	result+=float(Fraction(1, n)*(Fraction(1, 2)**(time)))
print(result)

Solution (Python):
import math

N, K = map(int, input().split())
s = 0
for n in range(1, N+1):
    if (n < K):
        nn = math.ceil(math.log2(K/n))
        s += 1/N * (1/2)**nn
    else:
        s += 1 / N

print(s)

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

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

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

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

per = 0
for i in range(1,n+1):
    p = i
    t = 0
    
    while(p < k):
        t += 1
        p = p*2

    
    if(t == 0):
        t = 0


        
    per +=1/n * (1/2 ** t)
    
print("{:}".format(per))

Solution (Python):
import math

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

naru = 0

for i in range(1, N+1):
    if i >= K:
        naru += 1
    else:
        kaisuu = math.ceil(math.log2(K / i))
        naru += 0.5 ** kaisuu

print("{:.12f}".format(naru / N))

Solution (Python):
import math

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


C = [math.ceil(math.log2((K - 1) // i + 1)) for i in range(1, N + 1)]
maxC = max(C)

P = [1.0] * (maxC + 1)
for i in range(1, maxC + 1):
    P[i] = P[i - 1] * 0.5

S = 0.0
for c in C:
    S += P[c]
print(S / N)