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):
n,k=[int(x) for x in input().split()]
bunshi=0
for i in range(1,min(k-1,n)+1):
    for j in range(20):
        if i*2**j>=k:
            bunshi+=2**(20-j)
            break
print("{0:.10f}".format(max(0,(n-k+1)/n)+bunshi/(n*2**20)))

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+=1
    ans+=(0.5**p)/n

print(ans)

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

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

prob = 0

s = 1
while N*s<K:
    s*=2

t = 0
for i in range(N,0,-1):
    if i*s>=K:
        t+=1
    else:
        s*=2
        t=t*2+1
        
print('{:.10f}'.format(t/s/N))

Solution (Python):

import numpy as np
from functools import lru_cache
import time,math

def main(): 
    if True:
        N,K = list(map(int, input().split()))
    else:
        N = 10**5
        K = 10**5
        N = 3
        K = 10


    sum = 0
    for n in range(N):
        
        if n+1 >= K:
            sum += 1/N
        else:
            sum += 1/((2**math.ceil(math.log2(K/(n+1))))*N)


    print(sum)
if __name__ =='__main__':
    main()

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

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

print('{:<20.16}'.format(p))

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

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

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

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

import math
total = 0
for i in range(1, n+1):
    x = max(math.ceil(math.log2(k / i)), 0)
    total += 1 / (n * 2 ** (x))
print(total)

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

Solution (Python):
N, K = list(map(int, input().split()))
total = 0.0
for n in range(1, N+1):
    a = 0
    while True:
        if n*(2**a) >= K:
            total += 1/(N*(2**a))
            break
        a += 1

print(total)

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

    p += (N-K+1)/N
        
print(p)

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

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

ans = 0


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

print(ans)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math

mod = 10**9+7

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

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

print(pro)

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

p = 0
for i in range(1, N + 1):
    if i >= K:
        p += (N - K + 1) / N
        break
    j = i
    p_ = 1
    while j < K:
        j *= 2
        p_ /= 2
    p += p_ / N

print(p)

Solution (Python):
import math
n, k = map(int, input().split())
print(sum(
        map(lambda i: 0.5 ** (math.ceil(math.log2(k/i))) if i < k else 1, list(range(1, n+1)))
) / n)

Solution (Python):
import sys

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

res = 0

for i in range(1, N+1):
    if i >= K:
        res += 1 / N
        continue

    p = 1
    while i < K:
        i *= 2
        p *= 0.5
    res += (1 / N) * p

print(res)

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

sho=k*2
slist=[]

while sho>=1:
    sho=sho/2
    slist.insert(0, sho)


nagasa=len(slist)
kaisulist=[]
now=0

for i in range(n):
    switch=0
    while switch==0:
        if now>=nagasa:
            switch=1
        elif i+1>=slist[now]:
            now+=1
        else:
            switch=1
    kaisulist.append(nagasa-now)


answer=0

for kl in kaisulist:
    answer+=(0.5**kl)

answer=answer/n
print(answer)

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

ans = 0
for i in range(1, N+1):
    tmp = float(1/N)
    now = i
    if now <= K-1:
        for k in range(100):
            now *= 2
            tmp *= float(1/2)
            if now >= K:
                break
    ans += tmp
print(ans)

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

ans = 0.0
for i in range(1, N + 1):
    point = i
    prob = 1.0 / N
    while point < K:
        point *= 2
        prob *= 0.5
    ans += prob

print(ans)

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

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

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


def ncount(k):
    count = 0
    cur = k
    while cur < K:
        cur <<= 1
        count += 1
    return count

print(sum(0.5 ** ncount(n) for n in range(1, N+1)) / N)

Solution (Python):
import math

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

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

ans2 = 0

for i in ans:
    ans2 += 1 / 2**i / N

print(ans2)

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

def f(i,k,n):
     if i<k:
          m = math.ceil(math.log2(k/i))
          return ((1/2)**m)/n
     else:
          return 1/n

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

print(ans)

Solution (Python):
from math import ceil,log2
N,K=[int(a) for a in input().split()]
b=0.0
for n in range(1,N+1):
    if n<K:
        a=ceil(log2(K/n))
        b+=pow(2,-a)
    else:
        b+=1
print(b/N)

Solution (Python):

"""
Created on Sun May 19 21:04:18 2019

@author: Yamazaki Kenichi
"""

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

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,K=MAP()

cnt=[0]*N
for i in range(1, N+1):
    j=i
    while j<K:
        j*=2
        cnt[i-1]+=1

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

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

print(sum(ans))

Solution (Python):
def count_i(i, k):
    sum_num = i
    counter = 0
    while k > sum_num:
        sum_num *= 2
        counter += 1
    return counter


def main():
    n, k = [int(e) for e in input().split()]
    prob_sum = 0
    for i in range(1, n+1):
        prob = 1 / n * (1 / 2) ** count_i(i, k)
        prob_sum += prob
    print(prob_sum)


if __name__ == "__main__":
    main()

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

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

print(total/N)

Solution (Python):
a, b = map(int,input().split())
c = 1 / a
l = []
for i in range(1,a+1):
  count = 0
  d = i
  while d < b:
    d = d*2
    count += 1
  num = c * (0.5**count)
  l.append(num)
print(sum(l))

Solution (Python):
import random
import math

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

def frontCounter(n, k):
	count = 0
	if n >= k:
		return count
	current = n
	while True:
		count += 1
		current = current * 2
		if current >= k:
			return count

probe = 0
for n in range(1, N + 1):
	probe += (1 / N) * math.pow(0.5, frontCounter(n, K))
print(probe)

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

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

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

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

ans = 0

for i in range(1, N+1):
    score = i
    rate = 1
    while(score < K):
        rate *= 0.5
        score *= 2
    ans += rate

print(ans/N)

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

Solution (Python):
n,k = map(int,input().split())
X = [0]*(n+1)
import math as ma
ans = 0
for i in range(1,n+1):
    temp = ma.ceil(ma.log2(k/i)) if k >  i else 0 
    ans += (1/n)*(0.5**temp)
print(ans)

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

Solution (Python):
import math
a,b=map(int,input().split())
ans=0.0
for i in range(1,a+1):
    
    
    temp = (1 / ((2**(max(1,math.ceil(math.log2(b/i)))))*a))
    if i >= b:
        temp = 1/a
    ans += temp
print(ans)

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

coin_num = [0]*(max(N,K)+1) 

cursor = K
count = 0
for i in range(len(coin_num)-1,0,-1):
    if i>=cursor:
        coin_num[i] = count
    else:
        while(i<cursor):
            cursor = (cursor+1)//2 
            count += 1
        coin_num[i] = count
        
ans = 0 
for i in range(1,N+1):
    ans += (1/N)*((1/2)**coin_num[i]) 
    
print(ans)

Solution (Python):
import math





def power2_larger(num):
        return len(str(bin(num-1))[2:])


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

ans = 0.
for i in range(N):
  if (i+1) >= K:
    ans += 1.0 / N
  else:
    var = int((K + i) / (i+1))
    var2 = power2_larger(var)
    ans += 1.0 / N / 2**var2
    
print(ans)

Solution (Python):
from math import *

n,k=map(int,input().split())
s=0
for i in range(1,n+1):
    x=ceil(log2(k/i))
    if x<0:
        s+=n-i+1
        break
    s+=0.5**x
print(s/n)

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

ans=0
base=1

for n in range(1,N+1):
    base=1
    while(n*base<K):
        base*=2
    ans+=1/(base*N)

print(ans)

Solution (Python):
import numpy as np
def calc(n, k):
    prob = 0
    for i in range(1, n+1):
        
        if i<k:
            time_to_win = int(np.ceil(np.log2(k/i)))
            prob += (1 / n) * (0.5**time_to_win)
        else:
            prob += (1/n) * (n- i+1)
            break
    return prob

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

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

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

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

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

print(prob)

Solution (Python):
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

n,k = m()

a = 1/n

su = 0
nn = 0
for i in range(1,n+1):
	kk = -(-k//i)
	n = 1
	while True:
		if kk <= n:
			break
		else:
			n = n * 2
			nn += 1
	su += a * ((1/2) ** nn)
	nn = 0

print(su)

Solution (Python):
import math

N, K = [int(s) for s in input().split(" ")]
p = 0
for n in range(1, N+1):
    if n >= K:
        p += 1/N
    else:
        p += 1/N * (0.5 ** (math.ceil(math.log2(K/n))))
print(p)

Solution (Python):
import sys
from math import *
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n, k = na()
def calc(i,k):
    ct = 0
    while i < k:
        i *= 2
        ct += 1
    return ct

s = 0
for i in range(1,n+1):
    s += pow(1/2,calc(i,k))
print((1/n) * s)

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

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

Solution (Python):
import sys
import math
def input(): return sys.stdin.readline().strip()

mi = lambda: map(int, input().split())

N, K = mi()

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

print(ans/N)

Solution (Python):

import itertools
from collections import Counter
from collections import defaultdict
import bisect
import math

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

    ans = 0.0
    if N < K:
        for i in range(1, N + 1):
            x = math.ceil(math.log2(K / i))
            
            ans += (1 / min(N, K)) * 0.5 ** x
    else:
        ans += (N - K + 1) / N
        for i in range(1, K):
            x = math.ceil(math.log2(K / i))
            
            ans += (1 / N) * 0.5 ** x

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

import sys
import math


def solve(N: int, K: int):
    k = K
    power2 = 1
    n = N
    total = 0
    while k > 0:
        if n < k:
            k = int(math.ceil(k / 2))
            power2 *= 0.5
            continue
        total += (n - k + 1) * power2
        n = k - 1
        power2 *= 0.5
        if k == 1:
            break
        k = int(math.ceil(k / 2))
    print(total / N)
    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())

bp = []
for i in range(30):
    bp.append(1/2**i)

res = 0
for i in range(1,n+1):
    if i>=k:
        res += 1/n
        continue
    x = i
    cnt = 0
    while x<k:
        x *= 2
        cnt += 1
    res += bp[cnt]/n

print("{:.12f}".format(res))

Solution (Python):
def task_c():
    n, k = map(int, input().split())
    from math import log2, ceil
    c = 0
    for i in range(1, n+1):
        if i >= k:
            c += 1/n
        else:
            c += 1/n * pow(0.5, ceil(log2(k / i)))
    print(c)
task_c()

Solution (Python):
from math import log2, ceil

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

for i in range(1, n + 1):
    if i >= k:
        ans += 1
        continue
    ans += 2 ** -ceil(log2(k / i))

print(ans / n)

Solution (Python):
import math

def main():
    buf = input()
    buflist = list(buf.split())
    N = int(buflist[0])
    K = int(buflist[1])
    divisor = N
    dividend = 0
    for i in range(N):
        dividend += 2 ** min(0, math.floor(math.log2(i+1) - math.log2(K)))
    print(dividend / divisor)

if __name__ == '__main__':
    main()

Solution (Python):
def func(i,K):
    od=0
    while(i*2**od<K):
        od+=1
    return 1/2**od

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













A = [0 for i in range(N+1)]
for i in range(1,N+1):
    A[i]=func(i,K)
print (sum(A)/N)

Solution (Python):
import math

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

K2 = math.log2(K)

out = sum([ (0.5) ** int(math.ceil(K2 - math.log2(me))) if me < K else 1 for me in range(1, N+1)]) / N

print(out)

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

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

Solution (Python):
import bisect
import math
def solve():
  n,k = (int(i) for i in input().split())
  bairitu = [1]
  for i in range(1,20):
    bairitu.append(2*bairitu[i-1])
  ans = 0
  kakuritu = 1/n
  for i in range(1,n+1):
    if i >= k:
      ans += kakuritu
    else:
      rest = math.ceil(k/i)
      place = bisect.bisect_left(bairitu,rest)
      ans += kakuritu *((1/2)**place)
  print(ans)
  
solve()

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

for n in range(1,min(K,N+1)):
    ans += 2**(20-math.ceil(math.log2(K/n)))

ans /= 2**20

ans += max(N-K+1,0)
ans /= N

print(ans)

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

ratio = 0
for i in range(N):
    dice = i+1
    tmp = dice
    tmp_ratio = 1.0 / N
        
    while(tmp < K):
        tmp = tmp * 2
        tmp_ratio *= 0.5
    ratio += tmp_ratio

print(ratio)

Solution (Python):
import math
n, k = map(int, input().split())
per_pro = 1/n
total = 0
if n >= k:
  total += per_pro * (n-k+1)
if n < k:
  for i in range(1, n+1):
    a = math.ceil(math.log(k/i, 2))
    total += per_pro * (1/2)**a
else:
  for i in range(1, k):
    a = math.ceil(math.log(k/i, 2))
    total += per_pro * (1/2)**a
print(total)

Solution (Python):
import math

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

z = 0

for n in range(1,(N+1)):
    k = max(math.ceil(math.log2(K / n)), 0)
    z = z + (1/N) * ((1/2) ** k)

print(z)

Solution (Python):
n,k=map(int,input().split())
ans=0
tmp=2**17
eps=10**(-10)
for i in range(1,n+1):
  if i>=k:
    ans+=1*tmp
  else:
    for j in range(1,18):
      if i*(2**j)>=k:
        ans+=tmp/(2**j)
        break
ans=ans/(n*tmp)
print(ans-eps)

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

l=[i+1 for i in range(N)]
L=[0 for i in range(N)]

for i in range(N):
    for j in range(30):
        if l[i]*(2**j)>=K:
            L[i]=1/(2**j)
            break

print(sum(L)/N)

Solution (Python):



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

import math



prob=max(N-K,0)
for M in range(1,min(N+1,K+1)):
	prob+=1/(2**math.ceil(math.log2(K/M)))
prob/=N
print(prob)

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

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

print(ans/N)

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

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

Solution (Python):


import math

def readInts():
  return [int(s) for s in input().split(" ")]

def calc(K, n):
  p = math.ceil(math.log2(K / n))
  return (1.0 / 2) ** p

def main():
  N, K = readInts()
  ans = 0.0
  for n in range(1, N+1):
    r = 1.0 / N
    if n < K:
      r *= calc(K, n)
    ans += r
  print(ans)

if __name__ == "__main__":
  main()

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:
        l = math.ceil(math.log2(k/i))
        p += (1/n) * ((1/2) ** l)

print(p)

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

def calc_pro(ini, K):
    ans = 0
    while 1:
        if K <= ini:
            return ans
        else:
            ini *= 2
            ans += 1

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

Solution (Python):
import sys

class SamInput(object):
    def __init__(self):
        self.inp = []
        for i in sys.stdin:
            i = i.replace("\n", "")
            j = list(i.split())
            self.inp.append(j)

    def readln(self):
        if len(self.inp) == 0:
            return False
        else:
            return str.join(" ", self.inp.pop(0))

    def read(self):
        if len(self.inp) == 0:
            return False
        while len(self.inp[0]) == 0:
            self.inp.pop(0)
            if len(self.inp) == 0:
                return False
        return self.inp[0].pop(0)

def main():
    inp = SamInput()
    N = int(inp.read())
    K = int(inp.read())

    ttl = 0

    for i in range(N):
        dc = i + 1
        ctr = 0
        while dc < K:
            ctr += 1
            dc *= 2
        ttl += (1/N * (0.5**ctr))

    print(ttl)

    

if __name__ == '__main__':
    main()

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

res = 0

left = K
right = N
n = 1


while left > N:
    n *= 2
    if left % 2 == 0:
        left = left // 2
    else:
        left = left // 2 + 1


while right > 0:
    res += (right - left + 1) / n
    n *= 2
    right = left - 1
    if left % 2 == 0:
        left = left // 2
    else:
        left = left // 2 + 1
    
print(res / N)

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

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

Solution (Python):
from math import log2, ceil

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

result = 0
for i in range(1, n+1):
    if i >= k:
        result += 1 / n
    else:
        m = ceil(log2(k / i))
        result += (1 / 2**m) / n

print(result)

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

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

cnt = 0
while 2 ** cnt < K:
    cnt += 1

res = 0
for i in range(1, N + 1):
    while i * (2 ** cnt) >= K and cnt >= 0:
        cnt -= 1
    cnt += 1
    res += 1 / ((2 ** cnt) * N)

print("{:.12g}".format(res))

Solution (Python):
n,k=map(int, input().split())
def sisu(num, goal):
    cnt = 0
    while num < goal:
        cnt+=1
        num*=2
    return cnt

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

print(ans/n)

Solution (Python):
import sys
import math
input = sys.stdin.readline
n,k = input().split()
n = int(n)
k = int(k)
ans = 0
if n < k:
    for i in range(1,n+1):
        s = math.log2(k / i)
        temp = (1 / 2) ** (math.ceil(s))
        ans += (temp / n)
else:
    for i in range(1,k+1):
        s = math.log2(k / i)
        temp = (1 / 2) ** (math.ceil(s))
        ans += (temp / n)
    ans += ((n - k) / n)
print(ans)

Solution (Python):
from math import ceil, log2


def main():
    N, K = map(int, input().split())
    prob = 0
    for n in range(1, N+1):
        m = ceil(log2(1.0 * K / n)) if n < K else 0
        prob += (1 / N) * (1 / 2) ** m
    print(prob)


if __name__ == '__main__':
    main()

Solution (Python):
import math
n, k = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    if i+1 >= k:
        dice = 0
    else:
        dice = math.ceil(math.log2(k/(i+1)))
    ans += (0.5 ** dice) /n

print(ans)

Solution (Python):
import numpy as np

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

Solution (Python):



def solve():
    n, k = map(int, input().split())
    ans = 0
    if n >= k:
        ans = (n - k + 1) / n
    al = [2 ** i for i in range(1, 18)]
    for i in range(1, min(n + 1, k)):
        for j in al:
            if i * j >= k:
                ans += (1 / n) * (1 / j)
                break
    print(ans)

if __name__=="__main__":
    solve()

Solution (Python):
import numpy as np
import math

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

ans = 0

for i in range(1, N+1):
    if (i < K):
        t = math.ceil(np.log2(K / i))
        ans += (1 / N) * np.power(0.5, t)
    else:
        ans += 1 / N

print(ans)

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if (self.parent[i] == i):
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if i < j:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def div_ceil(a, b):
    if a % b:
        return a // b + 1
    return a // b


def main():
    n, k = intin()

    scount = 0
    counts = defaultdict(int)

    for i in range(n, 0, -1):
        while k > i:
            k = div_ceil(k, 2)
            scount += 1
        counts[scount] += 1

    ans = 0.0

    for scount, ncount in counts.items():
        ans += (ncount / n) * (1 / (2**scount))

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):










import sys


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


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


def main():
    
    n, k = get_ints()
    ans = 0
    for i in range(1, n + 1):
        curr = (1 / n)
        x = i
        while x < k:
            x *= 2
            curr *= (1 / 2)
        ans += curr
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


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


def get_count(initial):
    cnt = 0
    point = initial
    while point < K:
        cnt += 1
        point *= 2
    return cnt


p = sum((1 / N) * 0.5 ** get_count(initial) for initial in range(1, N + 1))
print(p)

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

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

Solution (Python):
from decimal import Decimal
N, K = map(int, input().split())
ans = 0
for n in range(1, N + 1):
    c = 0
    while n < K:
        n = n << 1
        c += 1
    t = 1 << c
    ans += Decimal("1.0") / Decimal(str(N * t))
print(ans)

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

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

print(ans)