Problem:


Score : 300 points

Problem Statement

Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:

Throw the die. The current score is the result of the die.

As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.

The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.

You are given N and K. Find the probability that Snuke wins the game.

Constraints

1 ≤ N ≤ 10^5

1 ≤ K ≤ 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.

Sample Input 1

3 10

Sample Output 1

0.145833333333

If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^4 = \frac{1}{48}.

If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^3 = \frac{1}{24}.

If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^2 = \frac{1}{12}.

Thus, the probability that Snuke wins is \frac{1}{48} + \frac{1}{24} + \frac{1}{12} = \frac{7}{48} \simeq 0.1458333333.

Sample Input 2

100000 5

Sample Output 2

0.999973749998



Sample input:
3 10


Sample output:
0.145833333333

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
s = [0] * n
sum = 0
if n >= k:
  #k~nのn+1個は0回
  #k//2+1~k-1のk-k//2-1個は1回
  sum += (n-k+1)/n
  b = k-1
  for i in range(1,18):
    a = b
    if k//2**i==k/2**i:
      b = k//2**i-1
    else:
      b = k//2**i
    for l in range(b,a):
      s[l] = i
    sum += (a-b)/(n*2**i)
else:
  #k//2**i+1~nのn-k//2**i個はi回
  #k//2**(i+1)+1~k//2**iのk//2**i-k//2**(i+1)個はi+1回
  b = n
  for i in range(1,18):
    a = b
    if k//2**i == k/2**i:
      b = min(k//2**i-1,b)
    else:
      b = min(k//2**i,b)
    for l in range(b,a):
      s[l] = i
    sum += (a-b)/(n*2**i)
'''b = min(n,k)-1
for i in range(1,18): #1~k-1について
  a = b
  b = k//(2**i)-1
  if b > a:
    b = a
  for l in range(b,a):
    s[l] = i
    sum += 1/(n*2**i)'''
print(sum)

Submission status: Accepted

Solution code:

import math


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

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

print(P)

Submission status: Accepted

Solution code:

N,K=map(int,input().split())
ans = 0
#でた目をiとし出た目ごとに処理する
for i in range(1,N+1):
    count = 0
    kakuritu = 1/N
    while i < K :
        i = i *2
        kakuritu = kakuritu /2
    
    ans += kakuritu

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, raw_input().split())

res = 0.0

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

    while point < k:
        point *= 2
        count_head += 1

    res += (1.0/n) * (0.5 ** count_head)

print res

Submission status: Accepted

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

p = [0]*N

for i in range(1, N+1):
    p[i-1] = 1.0/N

    score = i

    while score < K:
        p[i-1] *= 0.5
        score *= 2

print(sum(p))

Submission status: Accepted

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

# n面サイコロ, 全て等確率

# k - 1である限りサイコロ1回振る => コインを続ける
# 面: 2倍
# 裏: ZERO

# 今回勝つ確率 => 1/2 で勝ち続けていくのを計測すればいい

point = 0

dice = float(1/ n)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

win_rate_sum = 0
for i in range(n):
    i += 1
    tmp_rate = 1/n
    while i < k:
        # print(i)
        i *= 2
        tmp_rate /= 2
    win_rate_sum += tmp_rate
print(win_rate_sum)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N, K = map(int, input().split())
print(sum([0.5**max(np.ceil(np.log2(K/i)), 0) for i in range(1, N+1)]) / N)

Submission status: Accepted

Solution code:
#import math

argN,argK = list(map(int,input().split()))

if argN < argK:
  ans = 0.0
else:
  ans = (argN - argK) / argN
#print(ans)

for i in range(1,min(argN,argK) + 1):
  check = i
  wkCount = 0
  while check < argK:
    check *= 2
    wkCount += 1
  ans += (1 / argN) * ((1 / 2) ** wkCount)
  #print(ans)

print(ans)

Submission status: Accepted

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

result =0

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

print(result/N)

Submission status: Accepted

Solution code:
import math

inputstrs = input().split()
n = int(inputstrs[0])
k = int(inputstrs[1])
p = map(lambda x: (0.5 ** math.ceil(math.log2(k) - math.log2(x + 1))) if x + 1 < k else 1, range(n))
print(sum(p) / n)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,k=map(int,input().split(" "))
p=0
count=[]
for i in range(1,n+1):
    p=1/n
    while i<k:
        i=2*i
        p=(1/2)*p
    count.append(p)
print(sum(count))

Submission status: Accepted

Solution code:
n,k =map(int, input().split())  #複数数値入力
ret = 0

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

Submission status: Accepted

Solution code:
import sys

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

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

        ans += 1 / N * (0.5)**cnt

    return ans


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import log2,ceil
N,K=map(int,(input().split()))
l=m=0
if N<K:
    for k in range(1,N+1):
        x=(0.5**ceil(log2(K/k)))/N
        l+=x
if N>=K:
    for k in range(1,K):
        x=(0.5**ceil(log2(K/k)))/N
        l+=x
    m=(N-K+1)/N
print (l+m)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, K = li_input()

    ans = 0

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

main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p_lis = []
for x in range(1,n+1):
    if k>x:
        i=1
        while x*2<k:
            x*=2
            i+=1
        p_lis.append(((1/2)**i)*(1/n))
    else:
        p_lis.append(1/n)
print(sum(p_lis))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(1, n+1):
    if i >= k:
        ans += 1/n
    else:
        count = 1
        while i * 2 ** count < k:
            count += 1
        ans += (1/n) * (0.5**count)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

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

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

print(p)

Submission status: Accepted

Solution code:
par = input().split()
N = int(par[0])
K = int(par[1])
i = 1
j = 1

countj = 0
tmpj = 0
counti = 0

while i <= N:
    j = 1
    j += tmpj
    while j < K:
        j *= 2
        countj += 1
    counti += (1/N) * ((1/2) ** countj)
    countj = 0
    tmpj += 1
    i += 1

print(counti)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
input1 = input().split()
n = input1[0]
k = input1[1]

n = int(n)
k = int(k)

me = 1 #さいころの目の変数
ten = 0#得点のカウント
count = 0 #いくらコインを連続させなきゃいけないかのカウント
total = 0 #確率はここに累積させる

while me <= n:
    ten = me
    while ten < k:
        count += 1
        ten = ten * 2
    total += 1/n * (1/2) ** count
    count = 0
    me += 1

print(total)

Submission status: Accepted

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

twoSquare = [2**i for i in range(21)]

ans = 0
for i in range(N):
    n = i+1
    high = 20
    low = 0
    while high!=low:
        #print(high, low)
        mid = (high+low)//2
        if n*twoSquare[mid] >= K:
            high = mid
        else:
            low = mid + 1
    ans += 1/N/twoSquare[high]
print(ans)

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())
prb = 0
#出た目をiとするとi*2**a > kとなる最小のaを知りたい
for i in range(1, n+1):
    if i < k:
        power = math.ceil(math.log2(k/i))
        prb += (1/n)*((1/2)**(power))
    else:
        prb += 1/n
print(prb)

Submission status: Accepted

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

cnt = 0
sumcl = []

for i in range(1,n+1) :
    pro = i
    while True :
        if pro < k :
            pro *= 2
            cnt += 1
        else :
            if i == 1 :
                top = cnt
                sumcl.append(1)
            else :
                sumcl.append(2**(top-cnt))
            cnt = 0
            break


print(decimal.Decimal(sum(sumcl)/(n*(2**top))))

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0

for i in range(N) : 
    n = i+1
    cnt = 0
    flag = 1
    if n >= K : flag = 0
    
    while(flag == 1) : 
        cnt += 1
        nn = n * (2 ** cnt)
        if(nn >= K) : 
            flag = 0
    
    sum += (1/2) ** cnt
sum = sum * (1/N)

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n =  list(map(int,input().split(' ')))

#print(n)
#ans =np.array([])
ans = []
for p in range(1,n[0]+1):
    c = 0
    while p < n[1]:
        p *= 2
        c+=1
#    print(c+1)
    ans.append((1/n[0])*(1/2)**(c+1))
#    np.append(ans,((1/n[0])*(1/2)**(c+1)))
#print(ans)   
print(sum(ans)*2)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
t = input().split()
n, k = int(t[0]), int(t[1])
ans = 1.0
for i in range(1, min(n + 1, k)):
    ki, cp = i, 1.0 / n * 0.5
    while ki < k:
        ki *= 2
        ans -= cp
        cp *= 0.5
print(ans)

Submission status: Accepted

Solution code:
import math
x, y = [int(i) for i in input().split()]

ans = 0
for i in range(1,x+1):
    if i >= y:
        ans += (1/x)*(x+1-i)
        break
    else:
        t = math.ceil(math.log2(y/i))
        ans += (1/x)*pow(0.5,t)

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
if n>=k:
    ans=(n-k+1)/n
        
else:
    ans=0.0
for i in range(1,min(n,k)+1):
        tmp=1.0
        while i<k:
            i=i*2
            tmp=tmp*0.5
        if tmp<1:
            ans+=tmp/n
print('{:.17g}'.format(ans))

Submission status: Accepted

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

ans = 0
for i in range(1, N + 1):
    if i >= K:
        ans += 1
    else:
        p = 1
        while i < K:
            i *= 2
            p *= 1 / 2
        ans += p
ans /= N
print(ans)

Submission status: Accepted

Solution code:
import bisect
two_ruijo_list = [2**i for i in range(18)]
N,K = map(int,input().split())
if K <= N:
    mi = K
    ans = (N-K+1)/N
else:
    mi = N+1
    ans = 0
#mi = min(N+1,K)
for i in range(1,mi):
    d = bisect.bisect_left([two_ruijo_list[j]*i for j in range(18)], K)
    ans += 0.5**d /N
print(ans)

Submission status: Accepted

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

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

ans = 0

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

Submission status: Accepted

Solution code:
import math

def main():
    N, K = map(int, input().split())
    probs = list()
    for i in range(1, N+1):
        p = math.pow(1/2, get_time(i, K))
        probs.append(p)
    p = sum(probs)/N
    print(p)

def get_time(num, goal):
    time = 0
    while(num < goal):
        num *= 2
        time += 1
    return time

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0.0
for i in range(1,N+1):
    cnt = 0
    while i < K:
        i *= 2
        cnt += 1
    ans += (1/N)*(0.5)**cnt
print(ans)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

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

print((1/N) * x)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
total_prob = 0
if N > K:
    total_prob = (N-K)/N
for i in range(1, min(N+1, K+1)):
    score = i
    prob = 1/N
    while score < K:
        prob *= 1/2
        score *= 2
    total_prob += prob
print(total_prob)

Submission status: Accepted

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

ans = 0
log = []
for n in range(1,N+1):
    r = 0
    while n < K:
        n *= 2
        r += 1
    ans += 0.5**(r)
    log.append(r)

    

print(ans/N)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(1, n+1):
    if i >= k:
        ans += 1 / n
    else:
        tmp = i
        cnt = 0
        while tmp < k:
            tmp *= 2;
            cnt += 1
        ans += (1/n) * (1/2)**cnt

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int, raw_input().split())
kiso=float(1)/N

ans=0

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

print ans

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

p = 0
v = 1.0/N
for i in range(1,N+1):
  #print(i)
  if i < K:
    s = i
    c = 0
    while s < K:
      s = s * 2
      #print('/',s)
      c += 1
    #print('c',c)
    p += v * pow(0.5,c)
  else:
    p += v
    
print(p)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
def inpl(): return list(map(int, input().split()))

N, K = inpl()
ans = 0
X = 17

for i in range(1, N+1):
    while X and i * 2**(X-1) >= K:
        X -= 1
    ans += .5 ** X

print(ans/N)

Submission status: Accepted

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

for i in range(1, n+1):
    count = 0
    if i >= k:
        ans += 1 / n
    else:
        count = 1
        while i * 2**count < k:
            count += 1
        num = (1/n) * (0.5**count)
        ans += num

print('{:.12f}'.format(ans))

Submission status: Accepted

Solution code:
from math import ceil

# 入力
N, K = map(int, input().split())

# サイコロの各目について勝率を求め、それらの和を解とする
ans = sum(
    1 / (2**((ceil(K / i) - 1).bit_length()))
    for i in range(1, N + 1)
) / N

# 出力
print(ans)

Submission status: Accepted

Solution code:
import sys

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

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

            ans += 1 / N * (0.5)**cnt

    return ans


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

Submission status: Accepted

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

prob = 0.0
for i in range(1, n + 1):
    probtmp = 1 / n
    itmp = i
    while k > itmp:
        itmp *= 2
        probtmp /= 2
    prob += probtmp

print(prob)

Submission status: Accepted

Solution code:
import math

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

m = [2**i for i in range(18)]

sum = 0

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

print(sum/n)

Submission status: Accepted

Solution code:
import math
n=input().split()
N=int(n[0])
K=int(n[1])
c = 0
for i in range(1,N+1):
    if i < K:
        if math.log2(K/i) % 1 == 0:
            a =int(math.log2(K/i))
            b = (1/2)**a
            c = b + c
        else:
            a =int(math.log2(K/i) + 1)
            b = (1/2)**a
            c = b + c
    if i >= K:
        c = c + 1
c = c/N
print(c)

Submission status: Accepted

Solution code:
import math

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

    p = 0.0
    for i in range(1, K):
        if i > N:
            break
        m = math.ceil(math.log2(K / i))
        p += 1 / N * 0.5 ** m

    for i in range(K, N + 1):
        p += 1 / N

    print(p)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import ceil
res = 0
N, K = map(int, input().split())
for n in range(1, N + 1):
    if n >= K:
        res += 1 / N
        continue
    val = ceil(K / n - 1)
    res += 1 / (2 ** (len(bin(val)) - 2) * N)
print(res)

Submission status: Accepted

Solution code:
import math 

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

prob=0

for i in range(1, n+1):
    po = math.ceil(math.log2(max(1, k/i)))
    prob += math.pow(1/2, po)*(1/n)
    
print(prob)

Submission status: Accepted

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

prob = 0

for i in range(1, N+1):
    j = i
    inverse_p = N
    while j < K:
        j *= 2
        inverse_p *= 2
    prob += 1/ inverse_p

print(prob)

Submission status: Accepted

Solution code:
a,b = map(int, input().split())

ret = 0

for i in range(1,a+1): # 1,2,...,a
	tmp = 1 / a #float
	now = i
	while now < b:
		now *= 2
		tmp /= 2
	ret += tmp

# print(ret)
print("{:.12f}".format(ret))

Submission status: Accepted

Solution code:
n,k = (int(i) for i in input().split())
num,x,N,ans,f = 0,[],n,0,1
while f:
    if k==1: f = 0
    if n>=k: x.append((n-k+1,num))
    n,k,num = min(n,k-1),(k+1)//2,num+1
for i,j in x: ans+=(2**(num-j))*i
print(1.0*ans/(N*(2**num)))

Submission status: Accepted

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

ans = 0.0
for i in range(1, n+1):
    d = i
    count = 1
    while d < k:
        d *= 2
        count *= 2
    ans += 1 / count

print(ans / n)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
i = 0
while (2**i) < K:
    i+= 1

numerator = 0
denominator = 2**i

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=[0 for i in range(20)]
m=[2**i for i in range(20)]
for i in range(n):
    for j in range(20):
        if m[j]*(i+1)>=k:
            l[j]+=1
            break
for i in range(19):
    l[i+1]+=l[i]*2
print(l[19]/(m[19]*n))

Submission status: Accepted

Solution code:
import math


import math


def main():
    N, K = map(int, input().split())
    ans = 0
    for i in range(N): 
        tmp = K / (i+1)
        a = math.log2(tmp)
        if a < 0:
            a = 0
        elif not a.is_integer():
            a = int(a) + 1
        '''
        if tmp.is_integer():
            tmp = int(tmp)
            if not (tmp and ):
                a = int(math.log2(tmp))
        else:
            a = int(math.log2(tmp)) + 1
        '''
        ans += 0.5 ** a
    ans /= N

    # print('{:.15f}'.format(ans))
    print(ans);


main()

Submission status: Accepted

Solution code:
import math


import math


def main():
    N, K = map(int, input().split())
    ans = 0
    for i in range(N): 
        tmp = K / (i+1)
        a = math.log2(tmp)
        if a < 0:
            a = 0
        elif not a.is_integer():
            a = int(a) + 1
        '''
        if tmp.is_integer():
            tmp = int(tmp)
            if not (tmp and ):
                a = int(math.log2(tmp))
        else:
            a = int(math.log2(tmp)) + 1
        '''
        ans += 0.5 ** a
    ans /= N

    print('{:.15f}'.format(ans))


main()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = 0
flag = False
prob = 1

for i in range(1,n+1):
  flag = False
  if i >= k:
    ans += 1/n
  else:
    while flag == False:
      prob *= 1/2
      i *= 2
      if i >= k:
        ans += prob/n
        flag = True
        prob = 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

saip = 1/N
ans = 0
for i in range(1, N+1):
    prob = saip
    score = i
    while score < K:
        score *= 2
        prob *= 1/2
    ans += prob

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = 0
pp = 1 / n

for i in range(1, n + 1):
    if k < i:
        p += pp
    else:
        c = 0
        b = i
        while b < k:
            b = b * 2
            c += 1
        p += pp * (0.5 ** c)

print(p)

Submission status: Accepted

Solution code:
def prob(n, k):
    ans = 0
    for i in range(1, n+1):
        now = i
        count = 0
        while (now < k):
            now *= 2
            count += 1
        ans += (0.5) ** count
    return ans / n

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


main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
b = 1.0 / n
ret = 0
while n > 0:
    t = max(n - k + 1, 0)
    ret += b * t
    n -= t
    k -= k // 2
    b *= 0.5
print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, k = LI()
    s = S()
    s[k-1] = s[k-1].lower()
    print("".join(s))

    return

#B
def B():
    s = S()
    a = int("".join(s[:2]))
    b = int("".join(s[2:]))
    if 0 < a <= 12:
        if 0 < b <= 12:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    elif a == 0:
        if 0 < b <= 12:
            print("YYMM")
        else:
            print("NA")
    else:
        if 0 < b <= 12:
            print("YYMM")
        else:
            print("NA")
    return

#C
def C():
    n, k = LI()
    ans = 0
    if k == 1:
        print(1)
        return
    nibuiti = [None for i in range(int(math.log2(k) + 1))]
    for num in range(int(math.log2(k) + 1)):
        if num == 0:
            nibuiti[num] = 1 / 2
            continue
        nibuiti[num] = nibuiti[num-1]/2
        
    for i in range(1, n + 1):
        if i >= k:
            ans += 1
            continue
        b = nibuiti[int(math.log2((k - 1) // i))]
        ans += b
    print(ans/n)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0.0
tmp=0
ex=0
for i in range(1,N+1):
  if i>=K:
    ans+=1/N
  else:
    tmp=i
    for a in  range(1,10**5):
      tmp*=2
      if tmp>=K:
        ex=a
        break
    ans+=(1/N)*(1/2)**ex
print(ans)

Submission status: Accepted

Solution code:
from math import pow

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

    print(ans)

Submission status: Accepted

Solution code:
from fractions import Fraction


a,b = map(int,input().split(" "))
total = 0

for i in range(1,a+1):
    j = 0
    still = True
    while still:
        if b <= i * (2 ** j):
            still = False
        else:
            j = j+1
    total += Fraction(1,a)*Fraction(1,2 ** j)

print(float(total))

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
import math
N, K = list(map(int, input().split()))
result = 0
for i in range(1, N+1):
  result += (1/N) * 0.5 ** math.ceil(math.log(math.ceil(K/i), 2))
print(result)

Submission status: Accepted

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

i = 1
result = 0
for i in range(1, N+1):
  temp = 1 / N
  now = i
  while now < K:
    now *= 2
    temp *= 0.5
  result += temp
  
print(result)

Submission status: Accepted

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

min = 0
max = 0
ans = 0
num = 1

while True:
    if 2 ** min >= k / n:
        break
    min += 1

while True:
    if 2 ** max >= k:
        break
    max += 1


#print(min,max)

for i in range(max,min-1,-1):
    #print(i)
    count = 0
    while num * 2 ** (i-1) < k or i == 0:
        count += 1
        #print("i = {},num = {}, count = {}".format(i,num,count))
        num += 1
        if num > n:
            break
    ans += count / (n * 2 ** i)

print(ans)