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):
from math import log
n,k=map(int,input().split())
if n<k:
    p=0
    for i in range(1,n+1):
        po=int(log(k/i,2))
        if i*(2**po)!=k:
            po+=1
        p+=(1/n)*((1/2)**po)
    print(p)
else:
    p=(n-k+1)/n
    for i in range(1,k):
        po=int(log(k/i,2))
        if i*(2**po)!=k:
            po+=1
        p+=(1/n)*((1/2)**po)
    print(p)

Solution (Python):
import math
n, k = [int(item) for item in input().split()]
max_n_k = max(n,k)
tk = k

logs = [0] * (max_n_k+1)
cnt = 0
while tk > 1:
    tk /= 2.0
    cnt += 1
    logs[int(math.ceil(tk))] = cnt 

cur = 0
for i in range(k+1):
    if logs[i] == 0 and i != k:
        logs[i] = cur
    if i == k:
        logs[i] = 0
        cur = 0
    else:
        cur = logs[i]

ans = 0
for i in range(1, n+1):
    ans += 1.0 / n * pow(0.5, logs[i])
print(ans)

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

if N >= K:
    p = N - K + 1
else:
    p = 0

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

print("{:>.20f}".format(p/N))

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

times_dic = {}
for i in range(1,N+1):
  times = 0
  if i < K:
    times = math.ceil(math.log2(K/i))

  if times not in times_dic:
    times_dic[times] = 1
  else:
    times_dic[times] += 1
  
prob=0  
for times in times_dic:
  prob += 0.5**times*times_dic[times]/N
print(prob)

Solution (Python):
from fractions import *

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


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

print("{:.12f}".format(a.numerator / (N * a.denominator)))

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

P = 0

for dice in range(1,N+1):
    d = dice 
    prob = 1/N

    while d < K:
        prob = prob*0.5
        d *= 2

    P += prob


print(P)

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

Solution (Python):
from math import *

n, k = [int(item) for item in input().split()]
ans = 0
for p in range(1, n + 1):

    if p >= k:
        ans += 1;
    else:
        x = ceil(log2(k) - log2(p))
        ans += 1.0 / (1 << x);
print(ans / n)

Solution (Python):

import sys
import math


def solve(N: int, K: int):
    ans = 0.0
    for i in range(1, N+1):
        n = math.ceil(math.log2(K/i))
        n = max(n, 0)
        ans += 1.0/(2**n)/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):
from sys import stdin
import numpy as np










N, K = [int(x) for x in stdin.readline().rstrip().split()]

prob = [-1]*200003
def f(n):
  if prob[n]!=-1:
    return prob[n]
  if n>=K:
    prob[n] = 1.0
    return 1.0
  
  prob[n] = f(2*n)/2.0
  return prob[n]
for i in range(N, 0, -1):
  f(i)
ans = sum(prob[1:N+1])/N
print(ans)

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

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

print(ans)

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

ans = 0

for i in range(N):
    deme = i+1
    point = deme
    m = 0
    while(True):
        if point >= K:
            break
        point *= 2
        m += 1
    ans += (1/N) * (1/2)**m

print(ans)

Solution (Python):
n,k = map(int,input().split())
l = []
for i in range(1,n+1):
  tmp = i
  prob = 1/n
  while tmp < k:
    tmp = tmp * 2
    prob = prob * 1/2
  l.append(prob)
print(sum(l))

Solution (Python):


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

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

print(sum(prob))

Solution (Python):
import math
a=list(map(int,input().split(" ")))
N=a[0]
K=a[1]

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


print((s+(N-upbd))/N)

Solution (Python):



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

Win_rate = 0
for i in range(1,N+1):
    POINT = i
    Ex_Val = 1/N
    Win_count = 0
    while K > POINT:
        POINT = POINT*2
        Win_count+=1
        
    Win_Val = (1/2)**Win_count
    Win_rate += Win_Val*Ex_Val

print(Win_rate)

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


ans = 0.0
for i in range(1, n + 1):
  
  point = i
  tmp = 0.5
  while (point <  k):
    tmp = tmp * 0.5
    point = point * 2
  tmp = tmp / 0.5
  
  ans += 1.0 / float(n) * tmp
print(ans)

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

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

Solution (Python):
import math
n, k=[int(x) for x in input().split()]
s=0.0
cs=[0]*n
for i in range(1, n+1):
    c=0
    t=i
    while t<k:
        c+=1
        t*=2
    s+=1/(2 ** c)
print(s/n)

Solution (Python):
from math import *

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

Solution (Python):
N, K = map(int, input().split())
kaijo = [i for i in range(N)]
for i in range(1, N + 1):
    tmp = i
    j = 0
    while True:
        if tmp >= K:
            kaijo[i - 1] = j
            break
        tmp *= 2
        j += 1
ans = sum(pow(0.5, i) for i in kaijo)
print(ans / N)

Solution (Python):
import math

intlist = list(map(int, input().split()))
n = intlist[0]
k = intlist[1]

sum = 0.0

for i in range(n):
  if (i+1)<k:
    x = math.log2(k/(i+1))
    y = math.ceil(x)
    sum += 1 / n / (2**y) 
    
  else:
    sum += 1/n
    
print(sum)

Solution (Python):
import math

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

print(ans)

Solution (Python):
from math import log2, ceil

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

M = min(N, K)
ans = sum([0.5 ** ceil(log2(K) - log2(n)) for n in range(1,M+1)])
ans += max(N-K, 0)
ans /= float(N)

print(ans)

Solution (Python):
N, M = map(int, input().split())
ans = 0
a = 1
n = 0
while a < M:
    a *= 2
    n += 1
for i in range(N):
    score = i + 1
    if((a/2*score) >= M and n > 0): 
        a = a // 2
        n = n-1
    ans += (1/N) * pow(0.5, n)
print(ans)

Solution (Python):
a, b = map(int ,input().split())
c = 0

def fun(x, y):
    for i in range(y):
        if(x * 2**i >= y):
            return i
ans = 0
for i in range(a):
    ans += (0.5)**fun(i+1, b)
print(ans/a)

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

def renzoku(m):
    return pow(0.5,m)

def get_r(j):
    c = 0
    while True:
        if j >= k:
            return c
        c += 1
        j *= 2

result = 0
for i in range(n):
    i += 1
    result += (1.0/n) * renzoku(get_r(i))
print(result)

Solution (Python):
a = input().split()
n = int(a[0])
k = int(a[1])

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

print(ans/n)

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

total = 0

for i in range(1, n+1):
    base = i
    count = 0
    while k > base:
        base = base * 2
        count += 1
    total += (1 / n) * ((1 / 2) ** count)

print(total)

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

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

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

ans = u / n
print(ans)

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

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

  ans+=(1/n)*(1/2)**kaisu

print(ans)

Solution (Python):
def main():
    n, k = map(int, input().split())
    print(solve(n, k))

def solve(n, k):
    p = 0

    for x in range(1, n + 1):
        p += 1 / n * prob(x, k)
    
    return p

def prob(x, k):
    p = 1
    while x < k:
        x *= 2
        p /= 2
    
    return p

main()

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

score = 0
for i in range(1, N+1):
    point = i
    if point >= K:
        score += 1/N
    else:
        sisuu = 0
        while point < K:
            sisuu += 1
            point = point * 2
        score += 1/N / (2**sisuu)

print(score)

Solution (Python):



from math import log2,ceil

intext1 = input()
[n, k] = map(int, intext1.split())

kakuritu = 0.0
for v in range(1, n+1):
    if v >= k:
        tmp_kakuritu = 1 / n
        kakuritu += tmp_kakuritu
    else:
        x = ceil(log2(k/v))
        
        tmp_kakuritu = 1 / n / 2**x
        kakuritu += tmp_kakuritu

print(kakuritu)

Solution (Python):
import math

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

ans = 0
for s in range(1, n+1):
    heads2win = math.ceil(math.log2(k / s))
    ans += (1/n) * min(1, (1/2)**heads2win)

print(ans)

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

print(round(ans, 12))

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

prob=0

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

print(prob)

Solution (Python):
from sys import stdin

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

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

ans /= n
print(ans)

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

win_ratio = 0
nn = n
for saikoro in range(1,n+1):
    nn = saikoro
    coin_cnt = 0
    while True:
        if nn  >= k:
            break
        nn = nn * 2
        coin_cnt += 1
    win_ratio += (1/n) * (1/(pow(2, coin_cnt)))

print(win_ratio)

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

ret = 0

for i in range(N):
    if (i + 1) < K:
        ret += (1.0 / N) * (0.5 ** (math.ceil(math.log2(K / (i+1)))))
    else:
        ret += (1.0 / N)
print(ret)

Solution (Python):
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()

l = [pow(2,i) for i in range(1,30)]
cnt = [0]*(N+1)
data = [0]*(N+1)

for i in range(1,N+1):
    if i >= K:
        break
    for j in range(len(l)):
        if l[j]*i >= K:
            cnt[i] = j+1
            break
ans = 0
for i in range(1,N+1):
    data[i] = (1/N)*((1/2)**cnt[i])
    ans += data[i]

print(ans)

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

Solution (Python):
N, K = map(int, input().split())
dice = 0
score = 0
percent = 0
cnt = 0
ans = 0

for dice in range(1,N+1):
  score = dice
  cnt = 0
  percent = 0
  while score < K:
    score = score * 2
    cnt += 1
  percent = (1/N) * (0.5 ** cnt)
  ans += percent

print(round(ans, 12))

Solution (Python):

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

Solution (Python):
[n,k]=input().split()
n,k=int(n),int(k)
out=0
for iii in range(n):
  point=iii+1
  sum=1
  while point < k:
    point=point*2
    sum=sum*(1/2)    
  out+=sum/n
print(out)

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

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits



def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


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


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



sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n, k = MAP()

lis=[]

for x in range(1, n+1):
    tmp=0
    while x < k:
        x *= 2
        tmp+=1

    lis.append(float(1/(2**tmp)))


print(float(sum(lis)/n))

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

Solution (Python):
N, K = map(int, input().split())
win = []
for i in range(N):
    a = i+1
    count = 0
    while a < K:
        a = a*2
        count += 1
    A = (1/N) * (1/2)**count
    win.append(A)
B = sum(win)
print(B)

Solution (Python):



v = list(map(int, input().split()))
n, k = v[0], v[1]

result = 0
for i in range(n):
	p = 1/n
	need = 0
	num = i+1
	while True:
		if num >= k :
			break
		else :
			num *= 2
			need += 1
	p *= pow(1/2, need)
	result += p

print(result)

Solution (Python):
N, K = map(int, input().split())
ret = 0.0
tmp = 0
for i in range(1, N+1):
    c = (1/N)
    for j in range(K):
        if K <= i * (2**j):
            ret += (1/2) ** j
            break
print(ret/N)

Solution (Python):
A = list(map(lambda x: int(x),input().split()))
N = A[0]
K = A[1]

start = range(1,N+1)
ex = 0.0
for i in start:
    score = i
    p = 1.0
    cointoss = 0.0
    while K>score:
        score *= 2
        cointoss +=1
    a  =repr(p * 0.5 ** cointoss)
    
    ex += float(a)

print(repr(ex/float(N)))

Solution (Python):
a, b = map(int, input().split())
ans = 0
if(a >= b):
    ans += (a - b + 1) / a

k = []
s = b - 1
while(s >= 1):
    k.append(int(s))
    s /= 2

cnt = len(k) - 1
m = min(a, b - 1)
for i in range(1, m + 1):
    if(i > k[cnt]):
        cnt -= 1
    ans += (1/a) * (1/2) ** (cnt + 1)

print(ans)

Solution (Python):
import math
from decimal import *
N,K = [int(x) for x in input().split()]
ans = 0
lk = math.log(K)
l2 = math.log(2)
for i in range(1,N+1):
    if(i>=K):
        ans+=1
    else:
        l=1
        while(i*2**l<K):
            l+=1
        ans += Decimal(0.5**l)
print(ans/N)

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

Solution (Python):
import math 

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

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

Solution (Python):
import math

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

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

Solution (Python):
import math
N, K = (int(i) for i in input().split())  
ans = 0
for i in range(1, N+1):
    M = max(0, math.ceil(math.log2(K/(i))))
    ans += (0.5 ** M) / N
print(ans)

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

def cnt(i,k):
    cnt = 0
    while 1:
        i *= 2
        cnt += 1
        if i>=k: break
    return cnt

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

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

print(ans)

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

Solution (Python):
import math

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


kakuritsu = []
for x in range(1, N + 1):
    if x >= K:
        kakuritsu.append(1 / N)
        continue

    kaisu = math.ceil(math.log(K / x, 2))
    kakuritsu.append(1 / N * pow(0.5, kaisu))

print(sum(kakuritsu))

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

if K == 1:
  print(float(1))
else:
  prob = []
  for i in range(1, N+1):
    if i >= K:
      prob.append(1/N)
    else:
      prob.append(round(1/N * 0.5 ** (math.ceil(math.log(K/i)/math.log(2))), 12))
  print(sum(prob))

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

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

print(p)

Solution (Python):
import math

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

for n in range(1,N+1):
    if n<K:
        x = math.ceil(math.log2(K/n))
        ans += 1/(N*2**x)
    else:
        ans += 1/N

print(ans)

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

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

bw = [ 2**i for i in range(22)]

ans = 0.0

for i in range(1,N+1):
    for j in range(22):
        if(K<=i*bw[j]):
            ans += 1.0/bw[j]
            break

print(ans/N)

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

sum1 = 0
for i in range(n):
    cnt = 0
    s = i + 1
    if s >= k:
        sum1 += 1/n
    else:
        while True:
            s *= 2
            cnt += 1
            if s >= k:
                break
        sum1 += 1/n * 0.5**cnt
    
print(sum1)

Solution (Python):
import math

def original_ceil(n):
    return max(0, math.ceil(n))

n, k = [int(i) for i in input().split()]
max_p = original_ceil(math.log2(k))
list_p = [pow(2, i) for i in range(max_p + 1)]
bunbo = n * list_p[-1]
bunshi = sum([list_p[- original_ceil(math.log2((k/(i + 1)))) - 1] for i in range(n)])
print(bunshi / bunbo)

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

Solution (Python):
from __future__ import division

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

ans = 0
for score in xrange(1, n + 1):
    if score >= k:
        ans += 1 / n
        continue

    flips = 0
    while score < k:
        score <<= 1
        flips += 1

    x = 1 / pow(2, flips)
    y = 1 / n
    z = x * y
    ans += z

print "{0:.13f}".format(ans)

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

Solution (Python):
import math

N, K = map(int, input().split())
N_ = 1 / N
ans = 0
coin_continue = 0
for j in range(1, N+1):
    tmp = math.ceil(math.log2(K / j))
    if tmp > 0:
        coin_continue = tmp
    else:
        coin_continue = 0
    
    ans += (1 / 2) ** coin_continue
print(ans * N_)

Solution (Python):
import math


if __name__ == '__main__':
    N, K = map(int, input().split())

    answer = 0
    for A1 in range(1, N+1):
        if A1 >= K:
            answer += 1.0 / N
        else:
            k = math.ceil(math.log2(K/A1))
            answer += 1.0 / N * math.pow(0.5, k)
    print(answer)

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

point = 1/float(N)
coin = 0.5
win = 0
for i in range(N):
  if(K == 1):
    win = 1.0
    break
  if(i+1 >= K):
    win += point
  else:
    tmp = coin
    j = 1
    while ((i + 1) * pow(2,j) < K):
      tmp = tmp * coin
      j += 1
    win += point * tmp
print(win)

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


ans = 0

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

ans /= N
print(ans)

Solution (Python):
n, k = map(int, input().split())
ret = 0
for die in range(1, n + 1):
    prob = 1 / n
    if die >= k:
        ret += prob
    else:
        cur = die
        p = 0
        while cur < k:
            cur <<= 1
            p += 1
        ret += prob * (0.5 ** p)
print(ret)

Solution (Python):
number = input().split()
num = 0
answer = 0
count = 0

for i in range(int(number[0])):
    num = i + 1
    while num < int(number[1]):
        num *= 2
        count += 1
    answer += 1 / int(number[0]) * (0.5)**count
    count = 0

print(answer)

Solution (Python):
n,k=[int(x) for x in input().split(" ")]
ans=0.0
for i in range(1, n+1):
    if i<k:
        j=i
        count=0
        while j<k:
            j*=2
            count+=1
        ans += (1/n)*(1/2)**count
    else:
        ans += (n-k+1)*(1/n)
        break
print(ans)

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

sum = 0
for me in range(1, int(n)+1):
    if me < k:
        sum += (1/n) * pow(0.5, math.ceil(math.log(k/me, 2)))
    else:
        sum += (1/n)

print(sum)

Solution (Python):

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, K = read_ints()

from math import log2

ans = 0.0
p_dice = 1 / N


def get_trial(i):
    
    ret = 0
    tmp = i
    while tmp < K:
        tmp *= 2
        ret += 1

    return ret


for i in range(N):
    ans += (1 / 2)**get_trial(i+1)

print(p_dice*ans)

Solution (Python):
n,k=map(int,input().split())
ans=0
def cal(p,q):
    cnt=0
    while p<q:
        p*=2
        cnt+=1
    return cnt

if n<=k-1:
    x=n
else:
    x=k-1
    ans+=((n-k+1)/n)
for i in range(1,x+1):
    key=cal(i,k)
    ans+=(1/n)*(1/(2**key))
print(ans)

Solution (Python):



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

    for i in range(1, n + 1):
        if i >= k:
            ans += 1
        else:
            m = 1

            while i * 2 ** m < k:
                m += 1

            ans += (1 / 2) ** m

    print(ans / n)


if __name__ == '__main__':
    main()

Solution (Python):

a = list(map(int, input().split()))
kakuritu = 0
for N in range(a[0]):
    N = N+1
    count = 0
    if N >= a[1]:
        kakuritu = kakuritu + 1/a[0]
    else:
        while True:
            N=N*2
            count = count + 1
            if N >= a[1]:
                kakuritu = kakuritu + (1/2)**count/a[0]
                break

print(kakuritu)

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

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



count=0

for i in range(n):
    if i+1>=k:
        count+=1/n
    else:
        tmp=np.ceil(math.log2(k/(i+1)))
        
        count+=(1/n)*((1/2)**tmp)
print(count)

Solution (Python):
from sys import stdin

def solve(n, k):
    
    
    s = 0
    for dice in range(1, 1 + n):
        coin = 0
        while dice * (2 ** (coin - 1)) < k:
            coin = coin + 1
        
        coin = max(0, coin - 1)
        percentage = 1 / 2 ** coin
        s = s + 1 / n * percentage
    return s


def main():
    n, k = [int(n) for n in stdin.readlines()[0].strip().split(' ')]
    ans = solve(n, k)
    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
import math
from fractions import Fraction
n, k = map(int, input().split())
ans = Fraction()
for s in range(1, n+1):
    p = math.ceil(math.log2(k) - math.log2(s))
    if p < 1:
        ans += Fraction(1, n)
    else:
        ans += Fraction(1, n * (2 ** p))
print(float(ans))

Solution (Python):
import sys, math

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

immediate_win = (N - (K - 1)) / N if K <= N else 0

s = 0
for k in range(1, min(K - 1, N) + 1):
    r = K / k
    c = math.ceil(math.log2(r))
    p = 0.5 ** c
    s += p / N
print(s + immediate_win)

Solution (Python):
from sys import exit
import math

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

a = 0
b = []

for i in range(N):
    if i + 1 == K:
        
        a = N - K + 1
        break

    if math.ceil(math.log2(K / (i + 1))) >= 0:
        b.append(1/N * (1/2)**math.ceil(math.log2(K / (i + 1))))
    else:
        b.append(1/N)

ans = a / N + sum(b)

print(ans)

Solution (Python):
import math
N,K = [int(i) for i in input().split()]

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

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

ans = 0
nanjo = 0
a = True
tmp = n
while(a):
    if(tmp>=k):
        a = False
    else:
        tmp *= 2
        nanjo += 1

for i in range(n):
    tmp = n - i
    if (tmp >= k):
        ans += 1
    else:
        if(tmp * pow(2, nanjo) >= k):
            ans += pow(1 / 2, nanjo)
        else:
            nanjo += 1
            ans += pow(1 / 2, nanjo)

ans = ans / n
print(ans)

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

possibility = []
for i in range(1, N+1):
    for j in range(K):
        if i * 2 ** j >= K:
            temp = j
            break
    possibility.append(1 / N * (1 / 2) ** j)

print(sum(possibility))

Solution (Python):
a,b=tuple(map(int,input().split()))
cnt=0
for i in range(1,a+1):
    q=i
    cont=0
    while True:
        if q>=b:
            break
        cont+=1
        q*=2
    cnt+=1/a*(1/2)**cont
    
print(cnt)

Solution (Python):
import math
N,K=[int(h) for h in input().split()]


ans=0

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

print(ans)

Solution (Python):
import sys
import math

a = []
for l in sys.stdin:
    a.append(l)

_input = a[0]

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

each_result = max(n-k+1, 0) * (1/n)

for each_n in range(1, min(n+1, k)):
    each_time = math.ceil(math.log2(k/each_n))
    each_result += 1/n * (1/2) ** each_time

print(each_result)

Solution (Python):

N,K = map(int,input().split())
pw = 1
ans = 0
for n in range(1,N+1)[::-1]:
    while(pw * n< K):
        pw *= 2
    
    ans += 1.0/pw
print (ans/N)

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

li = []
for i in range(1, N+1):
    score = i
    kakuritu = 1/N
    shisu = 0
    while score < K:
        score *= 2
        shisu += 1
    coin_kakuritu = (0.5**shisu)
    kakuritu *= coin_kakuritu
    li.append(kakuritu)
print(sum(li))

Solution (Python):
N, K = map(int, input().split())
ans = 0
for i in range(1, N+1)[::-1]:
    total = i
    j = 1
    if i >= K:
        ans += 1/N
        continue
    while K > total * 2:
        total = total * 2
        j += 1
    ans += (1/N) * ((1/2) ** j)
print(ans)

Solution (Python):
N,K = map(int,input().split())
twos = [2]
a = 2
per = 0

while True:
    if a > 100000:
        break
    a = a*2
    twos.append(a)

for i in range(N):
    b = K / (i+1)
    if b <= 1:
        per += 1/N
    else:
        for j in range(len(twos)):
            if twos[j] >= b:
                per += 1/N * (1/2) ** (j+1)
                break
        

print(per)

Solution (Python):
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
if N >= K -1:
    S = N - (K-1)
else:
    S = 0
unit = 1
while K > 1:
    prev_K = K
    K = (K-1)//2 + 1
    unit /= 2
    if K > N:
        continue
    else:
        n = min(prev_K,N+1) - K
        S += unit * n
print(S/N)

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

for n in range(1,N+1):
  if(n >= K):
    res = res/N + (N-K+1)/N
    print('{:.14g}'.format(res))
    sys.exit()
  res += pow(1/2, math.ceil(math.log2(K/n)))

print('{:.14g}'.format(res / N) )

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

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

print(count)

Solution (Python):
import math

def get_pwr(i, k):
  if i < k:
    return math.ceil(math.log2(k/i))
  else:
    return 0

n, k = map(int, input().split(' '))
print(sum(1/(n*(2**get_pwr(i, k))) for i in range(1, n+1)))

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