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:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
from operator import mul

INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 組合せnCr
def combinations_count(n, r):
    if n < r:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

# ここから書き始める
n, k = map(int, input().split())
ans = 0
for i in range(1, n + 1):
    cnt = 0
    while i * 2 ** cnt < k:
        cnt += 1
    # print("cnt =", cnt)
    ans += (1 / n) * 0.5 ** cnt 
print(ans)

Submission status: Accepted

Solution code:
from decimal import Decimal
n,k=map(int,input().split())
ans=0
ans+=Decimal(max(0,(n+1-k))/n)
for i in range(1,min(k,n+1)):
    tmp=i
    tt=Decimal(1/n)
    while 0<tmp<k:
        tmp*=2
        tt=Decimal(tt/2)
        if tmp>=k:
            ans+=Decimal(tt)
print(Decimal(ans))

Submission status: Accepted

Solution code:
import math

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

tmp = []
for i in range(1, n + 1):
    if i < k:
        num = (-1 * math.log2(k / i)) // 1 * -1 
        tmp.append(num)
    else:
        tmp.append(0)
        
ans = 0
for i in range(n):
    ans += 2**(tmp[0] - tmp[i])

print(ans / (n * 2**tmp[0]))

Submission status: Accepted

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

prob = []

for base in range(1, n+1):
  p = 0
  while (base < k):
    p += 1
    base = base * 2
  prob.append(Fraction(1, n * (2 ** p)))
print(Decimal(sum(prob).numerator / sum(prob).denominator))

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
    continue
  x=(1/n)*pow(2,-1*math.ceil(math.log2(k/i)))
  ans+=x
print(ans)

Submission status: Accepted

Solution code:
from fractions import Fraction
from decimal import Decimal

def twice_num(i, limit):
    count = 0
    while i < limit:
        i *= 2
        count += 1
    return count

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

    ans = 0

    for i in range(1, n+1):
        p = Fraction(1, n)

        num = twice_num(i, k)
        if num > 0:
            p *= Fraction(1, 2**num)
        ans += p

    ans = Decimal(ans.numerator) / Decimal(ans.denominator)
    print("{:.12f}".format(ans))


main()

Submission status: Accepted

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

ans = 0
for i in range(1,n+1):
    num = i
    cnt = 0
    while True:
        if num >= k: break
        num *= 2
        cnt += 1
    prob = 1/pow(2,cnt)
    ans += prob

ans /= n
print(ans)

Submission status: Accepted

Solution code:
import math


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

ans = max(0, (n-k+1)/n)
for i in range(1, n+1):
    if i >= k:
        break
    x = math.ceil(math.log2(k/i))
    ans += (1/n) * (1/2)**x
print(ans)

Submission status: Accepted

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
nums = []
ans = 0
for i in range(1, n+1):
    temp = i
    counter = 0
    while k > temp:
        temp *= 2
        counter += 1

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
from decimal import *

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

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    for i in range(1,N+1):
        if i>=K:
            ans+=1/N
            continue
        p=1/N
        j=i
        while  j<K:
            p*=0.5
            j*=2
        ans+=p
    print(ans)
    





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import log2, ceil
n, k = map(int, input().split())
dic = {}
for i in range(1, n + 1):
  x = max(0, ceil(log2(k / i)))
  dic.setdefault(x, 0)
  dic[x] += 1
res = 0
for i in dic:
  res += (dic[i] * (2 ** -i))
print(res / n)

Submission status: Accepted

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

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

Submission status: Accepted

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

qs = 0
for i in range(1, N+1):
    if i >= K:
        qs += 1/N
    elif i < K:
        q = 1/N
        while i < K:
            q *= 1/2
            i *= 2
        qs += q
print(qs)

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:
N, K = map(int, input().split())
border = []
inx = 0
while K > 1:
  border.append(K)
  K = (K + 1) >> 1
  inx += 1
border.append(1)
border.reverse()
pre = 1
cnt = []
for i in range(1, len(border)):
  if N < border[i]:
    cnt.append(N - pre + 1)
    break
  elif N == border[i]:
    cnt.append(border[i] - pre)
    cnt.append(1)
    break
  else:
    cnt.append(border[i] - pre)
    pre = border[i]
if N >= border[-1]:
  cnt.append(N - border[-1] + 1)
ans = 0
for c in cnt:
  ans += c * 0.5 ** inx
  inx -= 1
print(ans/N)

Submission status: Accepted

Solution code:
n,k=map(int,input().split());print(sum([1,4/2**len(bin(~-k//i))][i<k]for i in range(1,n+1))/n)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
print(sum([1,4/2**len(bin(~-k//i))][i<k] for i in range(1,n+1))/n)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=0
for i in range(1,n+1): p+=[1,4/2**len(bin(~-k//i))][i<k]
print(p/n)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=0
for i in range(1,n+1):
  if i<k: p+=4*0.5**len(bin(~-k//i))
  else: p+=1
print(p/n)

Submission status: Accepted

Solution code:
from fractions import Fraction
import math
n,k=list(map(int,input().split()))
ans=0
for i in range(1,n+1):
    if i>=k:
        ans+=(Fraction(1,n))
    else:
        x=int(math.log((k/i),2))
        if (k/i)%(2**x)!=0:
            x+=1
        ans+=Fraction(1,n*(2**x))
print(float(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
#n>=kの場合は最初のサイコロで勝ちになる可能性がある
if n>=k:
    ans=(n-k+1)/n#xはサイコロだけで勝ちになる確率
    for i in range(1,k):
        j=0
        while True:
            i*=2
            j+=1
            if i>=k:
                break
        ans+=(1/n)*(0.5)**j
else:
    ans=0
    for i in range(1,n+1):
        j=0
        while True:
            i*=2
            j+=1
            if i>=k:
                break
        ans+=(1/n)*(0.5)**j
print(ans)

Submission status: Accepted

Solution code:
n, k = [int(v) for v in input().split()]
rate = []
for i in range(1, n + 1):
    if i >= k:
        rate.append(1)
        continue

    for s in range(1, k):
        score = i * (2 ** s)
        if score >= k:
            rate.append(1 / (2 ** s))
            break

print(sum(rate) / len(rate))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
count = 0
E = 0
for i in range(N):
    count = 0
    while i+1 <= K-1:
        count += 1
        i = 2*i + 1
    E += (1/N)* (1/2)**count
if E <= 1:
    print(E)
else:
    print("1")

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

"""
i*2**t >= k
2**t >= k/i
tlog(2) >= log(k/i)
t >= log(k/i)/log(2)
"""

import math

ans = 0

for i in range(1,n+1):
    if i >= k:
        t = 0
    else:
        t = math.ceil(math.log(k/i)/math.log(2))
    ans += 1/pow(2, t)

ans /= n

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import*

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

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import ceil, log2

n, k = map(int, input().split())
print(sum(0.5 ** max(ceil(log2(k / i)), 0) for i in range(1, n + 1)) / n)

Submission status: Accepted

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

Submission status: Accepted

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

answer = 0
for value in range(1, N+1):
    number_of_front = 0
    while True:
        if value >= K:
            break
        value = value*2
        number_of_front += 1
    answer += 0.5 ** number_of_front

print(answer/N)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(n, k):
    ans = []
    for dice in range(1, n+1):
        c = 0
        while dice < k:
            dice *= 2
            c += 1
        ans.append((1/n) * 1/(2**c))

    return sum(ans)


if __name__ == '__main__':
    n, k = map(int, input().split())
    print(round(solve(n, k), 10))

Submission status: Accepted

Solution code:
def num(i,k):
    n=1
    while True:
        if i*2*(2**(n-1))>=k:
            return n
            break
        n+=1

n,k=map(int, input().split())
c=0
i=1
for i in range(1,n+1):
    if i>=k:
        c+=1
    elif i*2<k:
        c+=(1/2)**num(i,k)
    else:
        c+=(1/2)
print((1/n)*c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
ans=0
cnt=0#2欠けた階数
for i in range(n):
    while(n-i<k):
        k=(k+1)//2
        cnt+=1
    ans+=1/(2**cnt)/n
print(ans)

Submission status: Accepted

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

def check(now):
    if pow(2,now) * dice >= K:
        return True
    else:
        return False
#(l,r]
def bisec(l, r):
    if r - l == 1:
        return r
    mid = (l + r) // 2
    if check(mid):
        return bisec(l,mid)
    else:
        return bisec(mid,r)

ans = 0
for dice in range(1,N+1):
    ans += 1 / pow(2,bisec(-1,30))
print(ans/N)

Submission status: Accepted

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

def check(now):
    if pow(2,now) * dice >= K:
        return True
    else:
        return False
#(l,r]
def bisec(l, r):
    if r - l == 1:
        return r
    mid = (l + r) // 2
    if check(mid):
        return bisec(l,mid)
    else:
        return bisec(mid,r)

ans = 0
for dice in range(1,N+1):
    ans += 1 / pow(2,bisec(-1,100))
print(ans/N)

Submission status: Accepted

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


def check(now):
    if pow(2,now) * dice >= K:
        return True
    else:
        return False
#(l,r]
def bisec(l, r):
    if r - l == 1:
        return r
    mid = (l + r) // 2
    if check(mid):
        return bisec(l,mid)
    else:
        return bisec(mid,r)
ans = 0
for dice in range(1,N+1):
    ans += pow(1/2,bisec(-1,100))
print(ans/N)

Submission status: Accepted

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

rate = 0

import math

for dice in range(1,N+1):
    #まず dice点
    cnt = math.ceil(math.log2(K/dice))
    if cnt < 0:
        cnt = 0
    rate += pow(1/2,cnt)

print(rate/N)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


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


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


N, K = zz()
# if(N >= K):
#     ans = (N-K+1)/N
# else:
#     ans = 0
ans = 0.0
for n in range(1, N+1):
    # x = max(int(np.log2(K / n)) + 1, 0)
    x = 0
    while (n < K):
        n *= 2
        x += 1
    # print('n=', n, 'x=', x)
    tmp = 1/N * pow(1/2, x)
    ans += tmp
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = 0
for i in range(1, n+1):
    for j in range(100):
        if i*2**j>= k:
            a += 0.5**j
            break
print((1/n)*a)

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())
ans = 0
for i in range(1, n+1):
    x = math.ceil(math.log2(k/i))
    if x < 0:
        x = 0
    ans += (1/n) * (1/2)**x
print("{:.15f}".format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
import math
 
N,K=list(map(int,input().split()))
 
ans = 0
for n in range(1,N+1):
    p = np.log2(K/n)
    p = math.ceil(p)
    
    if p < 0:
        p=0
    
    ans_temp = (1/N)*(1/2)**p
    ans+=ans_temp
    
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
dk = [1,k,float("inf")]
ans = 0

while k > 2:
    k /= 2
    dk.append(int(-(-k//1)))
    
dk = sorted(dk)[::-1]
    
for i in range(1,n+1):
    for j in range(len(dk)):
        if i >= dk[j]:
            break
            
    ans += 1/n *(0.5**(j-1))
            
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

for i in range(1, min(N + 1, K)):
    y = math.ceil(math.log2(K / i))
    sum_ += pow(1 / 2, y) / N

print(sum_)

Submission status: Accepted

Solution code:
import math

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

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

    x = math.ceil(math.log(K/i,2))
    sum += (0.5 ** x)

print(sum / N)

Submission status: Accepted

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

ans = 0

for i in range(1, N+1):
    M = 1.0/N
    S = i
    while S < K:
        S *= 2
        M /= 2
    ans += M

print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
ans = 0
coin_num = 0 # コインを振る回数
for v in range(1,N+1):
    l_num = v
    while l_num < K:
        coin_num += 1
        l_num *= 2
    ans += (1/N) * (0.5 ** coin_num)
    coin_num = 0
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from decimal import Decimal
N, K = map(int, input().split())
t = 0
i = 1
while(i < K):
    t += 1
    i *= 2
under = 2**t

p = 0
for i in range(1, N+1):
    c = 0
    while(i < K):
        c += 1
        i *= 2
    p += 2**(t-c)
print(Decimal(p/((2**t)*N)))

Submission status: Accepted

Solution code:
from decimal import Decimal
N, K = map(int, input().split())
t = 0
i = 1
while(i < K):
    t += 1
    i *= 2
under = 2**t

p = 0
for i in range(1, N+1):
    c = 0
    while(i < K):
        c += 1
        i *= 2
    p += 2**(t-c)
print(Decimal(p)/Decimal((2**t)*N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from math import log2, ceil

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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

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

    print(ans / N)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
def binary(n, k):
  cnt = 0
  while 1 <= n <= k-1:
    cnt += 1
    n *= 2
    if n >= k:
      break
  return cnt
ans = 0
for i in range(1, n+1):
  ans += (1/n)*(1/2)**(binary(i, k))
print(ans)

Submission status: Accepted

Solution code:
import math

def main():
    n,k=map(int,input().split())
    s = 0
    for i in range(1, n+1):
        c=max(0, math.ceil(math.log(k/i, 2)))
        #print(c)
        s += (1/2)**c
    print(s/n)
    
if __name__ == "__main__":
    main()

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 += N+1-i
        break
    n = math.ceil(math.log2(K/i))
    ans += 0.5**n

print(ans/N)

Submission status: Accepted

Solution code:
import sys
import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
start=time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n,k = rl()
ans=0
for i in range(1,n+1):
    if i>=k:
        ans+=1/n
        continue
    if i>=k/2:
        ans+=1/2/n
        continue
    a=math.ceil(math.log2(k/i))
    ans+=(1/2)**a/n
    
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
z=1
for i in range(1,n+1):
  x=k/i
  cnt=0
  while x>1:
    cnt+=1
    x/=2
  if cnt!=0:
    z-=(1/n)*(1-1/(2**cnt))
print(z)

Submission status: Accepted

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

ans=0
for i in range(N):
    if K<=i:
        ans+=1/N
    else:
        a=math.ceil(math.log(K/(i+1),2))
        ans+=1/N*0.5**a
print(ans)

Submission status: Accepted

Solution code:
N,K  = map(int, input().split()) 
POINT = [0]*N
OK = [False]*N
Pro = [0]*30
for i in range(N):
    POINT[i] = i+1


for i in range(len(Pro)):
    for j in range(N):
        if OK[j] == False:
            if POINT[j]>=K:
                OK[j] = True
                Pro[i] += 1
            POINT[j] *=2

ans = 0
for i in range(len(Pro)):
    ans +=  Pro[i]/(2**i)

print(ans/N)

Submission status: Accepted

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

ans = 0
count = 0

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

print(ans/n)

Submission status: Accepted

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

def num(i):
    j = 0
    while i < K:
        i *= 2
        j += 1
    return j

for i in range(1, N+1):
    ans += float(1) / (N*2**num(i))
print(ans)

Submission status: Accepted

Solution code:
from math import log2, ceil

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

ans = 0
for i in range(1, n+1):
    d = ceil(k/i)
    head = ceil(log2(d))
    ans += (0.5**head)/n
print(ans)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    ans = 0
    for i in range(1, n+1):
        temp = i
        j = 0
        while temp < k:
            temp *= 2
            j += 1
        ans += (1/2)**j
    print(ans/n)


if __name__ == "__main__":
    main()

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
    else:
        m = math.ceil(math.log2(k/i)) # 必要な回数
        ans += 0.5**m
print(ans / n) # 最後に割る

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0
num = 1

while num < k:
    num *= 2
    cnt += 1

coin = 0

coin_num = k // 2


for i in range(1, n+1):
    num = i
    cnt = 0
    while num < k:
        num *= 2
        cnt += 1
    coin += float(0.5**cnt) 

print('{:.10f}'.format(coin / n))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n, k = geta(int)
    ans = 0
    for i in range(1, n+1):
        l = i
        while l < k:
            l *= 2
        ans += i/l/n

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(ans)