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())

answer = 0

for i in range(1, n + 1):
    score = i
    coin = 0
    while 1 <= score <= k - 1:
        score = score * 2
        coin += 1

    answer += (1 / n) * (0.5 ** coin)

print(answer)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N, K = map(int,input().split())
num = 0
total = float(0)
per = float(1)

for i in range(1, N + 1):
    if i < K:
        j = 1
        while True:
            num = i * pow(2, j)
            per = pow(0.5, j)
            if num >= K:
                total += 1.0 / N * per
                break
            else:
                j += 1
    else:
        total +=  1.0 / N
print(total)

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
p=0
for i in range(1,n+1):
    p0 = 1/n
    cp = i
    while True:
        if cp >= k:
            p += p0
            break
        else:
            cp *= 2
            p0 *= 1/2
print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N,K=(int(x) for x in input().split())
ans=0.0
for i in range(1,N+1):
  c=0 if i>=K else math.ceil(math.log2(K*1.0/i))
  ans+=0.5**c
print(ans/N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
pro = []
for i in range(1,n+1):
  a = i
  p = 1/n
  while a < k:
    a = a + a
    p = p * 0.5
  pro.append(p)
  
print(sum(pro))

Submission status: Accepted

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

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

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


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math as m
n,k=map(int,input().split())
p=0
for i in range(1,min(n+1,k)):
  r=m.ceil(m.log(k/i,2))
  p+=1/(2**r)
for _ in range(k,n+1):
  p+=1
print(p/n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

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

if n < k:
    for i in range(1, n + 1):
        ans += (0.5)**(math.ceil(math.log2(k / i)))

print(ans / n)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
e = 0
for i in range(1, a + 1):
    c = i
    d = 0.5
    if c >= b:
        e += 1 / a
    else:
        while True:
            c *= 2
            if c >= b:
                e += 1 / a * d
                break
            d = d * 1 / 2
print(e)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = 0
for i in range(1, n+1):
    sum_ = i
    j = 0
    while True:
        if sum_ >= k:
            break
        sum_ *= 2
        j += 1
    q = 1
    for x in range(j):
        q *= 0.5
    p += q
p /= n
print(p)

Submission status: Accepted

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

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:
n,k=map(int,input().split())
n_list = n
p = 0
c = 0
while k > 0.5 :
    num = max(int(n_list-k+1),0)
    if num:
        p += num * (0.5**c)
        n_list = int(k) - int(1 - ( k - int(k)))
    k /= 2
    c += 1
print( p / n )

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def winrate(wn, wk):
    b = 0
    c = wn
    while c < wk:
        b += 1
        c *= 2
    return 1/2 ** b

n, k = map(int,input().split())
ans = 0
for i in range(1, n+1):
    ans += 1/n * winrate(i, k)
print(ans)

Submission status: Accepted

Solution code:
def winrate(wn, wk):
    b = 0
    while wn * 2**b < wk:
        b += 1
    return 1/2 ** b

n, k = map(int,input().split())
ans = 0
for i in range(1, n+1):
    ans += 1/n * winrate(i, k)
print(ans)

Submission status: Accepted

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

sum_prob = 0
for init_num in range(1, N + 1):
    if init_num < K:
        n_trial_lower = 0
        while init_num * (2**n_trial_lower) < K:
            n_trial_lower += 1
        prob = 1 / N * (0.5**n_trial_lower)
    else:
        prob = 1 / N
    sum_prob += prob

print(sum_prob)

Submission status: Accepted

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

def required_coins(s, K):
    ans = 0
    while s < K:
        s <<= 1
        ans += 1
    return ans

A = [1/(1 << required_coins(i + 1, K)) for i in range(N)]
ans = sum(A) / N
print(ans)

Submission status: Accepted

Solution code:
# using main() makes code faster from the point of view of "access to variables in global name-space"
# def main():

""" convenient functions
# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
"""

import sys
sys.setrecursionlimit(10**7)
from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
# accumulate() returns iterator! to get list: list(accumulate())
from math import factorial, ceil, floor
def factorize(n):
    """return the factors of the Arg and count of each factor
    
    Args:
        n (long): number to be resolved into factors
    
    Returns:
        list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
    """
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
def combinations_count(n, r):
    """Return the number of selecting r pieces of items from n kinds of items.
    
    Args:
        n (long): number
        r (long): number
    
    Raises:
        Exception: not defined when n or r is negative
    
    Returns:
        long: number
    """
    # TODO: How should I do when n - r is negative?
    if n < 0 or r < 0:
        raise Exception('combinations_count(n, r) not defined when n or r is negative')
    if n - r < r: r = n - r
    if r < 0: return 0
    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 combinations_with_replacement_count(n, r):
    """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
    
    Args:
        n (long): number
        r (long): number
    
    Raises:
        Exception: not defined when n or r is negative
    
    Returns:
        long: number
    """
    if n < 0 or r < 0:
        raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
    elif n == 0:
        return 1
    else:
        return combinations_count(n + r - 1, r)
from bisect import bisect_left, bisect_right
from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from operator import itemgetter
# ex1: List.sort(key=itemgetter(1))
# ex2: sorted(tuples, key=itemgetter(1,2))
from functools import reduce
def chmin(x, y):
    """change minimum
    if x > y, x = y and return (x, True).
    convenient when solving problems of dp[i]
    
    Args:
        x (long): current minimum value
        y (long): potential minimum value
    
    Returns:
        (x, bool): (x, True) when updated, else (x, False)
    """
    if x > y:
        x = y
        return (x, True)
    else:
        return (x, False)
def chmax(x, y):
    """change maximum
    if x < y, x = y and return (x, True).
    convenient when solving problems of dp[i]
    
    Args:
        x (long): current maximum value
        y (long): potential maximum value
    
    Returns:
        (x, bool): (x, True) when updated, else (x, False)
    """
    if x < y:
        x = y
        return (x, True)
    else:
        return (x, False)

from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)

# first create factorial_list
# fac_list = mod_factorial_list(n)
INF = 10 ** 18
MOD = 10 ** 9 + 7
modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
def modinv(a, p = MOD):
    # evaluate reciprocal using Fermat's little theorem:
    # a**(p-1) is identical to 1 (mod p) when a and p is coprime
    return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
    if n <= 1:
        return [0,1][:n+1]
    else:
        inv_t = [0,1]
        for i in range(2, n+1):
            inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
        return inv_t
def modfactorial_list(n, p = MOD):
    if n == 0:
        return [1]
    else:
        l = [0] * (n+1)
        tmp = 1
        for i in range(1, n+1):
            tmp = tmp * i % p
            l[i] = tmp
        return l
def modcomb(n, k, fac_list = [], p = MOD):
    # fac_list = modfactorial_list(100)
    # print(modcomb(100, 5, modfactorial_list(100)))
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if len(fac_list) <= n:
        a = factorial(n) % p
        b = factorial(k) % p
        c = factorial(n-k) % p
    else:
        a = fac_list[n]
        b = fac_list[k]
        c = fac_list[n-k]
    return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
    return (a + b) % MOD
def modsub(a, b, p = MOD):
    return (a - b) % p
def modmul(a, b, p = MOD):
    return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
    return modmul(a, modpow(b, p-2, p))

""" initialize variables and set inputs
# initialize variables
    # to initialize list, use [0] * n
    # to initialize two dimentional array, use [[0] * N for _ in range(N)]
# set inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
# preprocessing
    # transpose = [x for x in zip(*data)]
    # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
    # flat = [flatten for inner in data for flatten in inner]
    # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
# calculate and output
    # output pattern
    # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
"""

# functions used
r = lambda: sys.stdin.readline().strip()
r_int = lambda: int(r())
R = lambda: list(map(int, r().split()))
Rfloat = lambda: list(map(float, r().split()))
Rtuple = lambda: tuple(map(int, r().split()))
Rmap = lambda: map(int, r().split())

""" how to treat input
# single int: int(r())
# single string: r()
# single float: float(r())
# line int: R()
# line string: r().split()
# line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
# lines int: [R() for _ in range(n)]
"""

# for test
# sys.stdin = open('sample.txt') 

# main
N, K = R()
ans = 0
for i in range(N):
    s = i + 1
    deno = N
    while s < K:
        s *= 2
        deno *= 2
    ans += 1/deno
print(ans)

"""memo: how to use defaultdict of list
# initialize
Dic = defaultdict(list)
# append
Dic[x].append(y)
# for
for k, v in Dic.items():
"""

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
l=[]
for i in range(1,N+1):
  score=i
  while 1<=score<=(K-1):
    score*=2
  prob=(1/N)*i/score
  l.append(prob)
print(sum(l))

Submission status: Accepted

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

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

Submission status: Accepted

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

p = 0
# for i in range(1, n + 1):
#     m = np.ceil(np.log2(k / i))
#     p += 1 / n * (1 / 2 ** m)

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

print(p)

"""
2**3 = 8
3 = np.log2(8)

n * 2**x = k
2**x = k / n
x = np.log2(k / n)
"""

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0.0
for i in range(1, N + 1):
    # 何回(s)連続表が出ればよいかを確認
    w = i
    s = 0
    while w < K:
        w *= 2
        s += 1

    # サイコロの目iが出る確率　×　i回連続表が出る確率　を足していく
    ans += (1 / N) * (1 / 2) ** s

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
Dataset = [2**i for i in range(18)]
def kakuritsu(n, K):
    for i, data in enumerate(Dataset):
        if n*data >= K:
            return (1/2)**i

N, K = map(int, input().split())
total = 0
for i in range(1, N+1):
    total += kakuritsu(i, K)
print(total/N)

Submission status: Accepted

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

Submission status: Accepted

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

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

up_bound = K-1
low_bound = up_bound // 2
now_zoom = 1/2
while up_bound != 0:
    if up_bound <= N:
        ans += now_zoom * (up_bound - low_bound) / N
    elif low_bound <= N:
        ans += (N-low_bound)*now_zoom/N
    up_bound = low_bound
    low_bound = up_bound // 2
    now_zoom *= 1/2
print(ans)

Submission status: Accepted

Solution code:
inf = input().split()
N = int(inf[0])
K = int(inf[1])
ans = 0

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

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

Submission status: Accepted

Solution code:
from math import log2
N, K = map(int, input().split())
p = 0.0
if N >= K:
    p1 = (N-K+1)/N
    p2 = 1.0
    p += p1
    temp = 0.0
    for i in range(1, K): # 1 to K-1
        n = int(log2(K-1)-log2(i))+1
        temp += (0.5)**n
    p2 *= temp*(1/N)
    p += p2
else:
    temp = 0
    for i in range(1, N+1): # 1 to N
        n = int(log2(K-1)-log2(i))+1
        temp += (0.5)**n
    p = temp*(1.0/N)
print(p)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A=N
total=0
count=1
flag=0
if N>=K:
   total=(N-K+1)/N
   
   N=K-1
if N<K:
    while(flag==0):
        if(K/2<1):
            flag=1
        if K%2==1:
            K = K//2+1
        elif K%2==0:
            K = K // 2
        if N>=K:

            total += (N-K+1)*1/(A*2**count)
            N=N-(N-K+1)

        count += 1
    print(total)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

    size = int(math.log2(K)+2)
    table = [1 / 2 ** i for i in range(size)]
    p = 0
    for i in range(1, N+1):
        point = i
        j = 0
        while point < K:
            point *= 2
            j += 1
        p += table[j]
    print(p/N)

    

main()

Submission status: Accepted

Solution code:
import numpy as np

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

ans = np.zeros(n)

for i in range(n):
    ans[i] = 1.0

for i in range(n):
    tmp = i+1
    while(tmp < k):
        ans[i]*=0.5
        tmp*=2


print(np.sum(ans)/n)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import bisect
from collections import defaultdict
import math

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

    prob = 0
    for n in range(N):
        n += 1
        if n >= K:
            p = 1.0
        else:
            min_val = math.ceil(math.log2(K / n))
            p = 0.5 ** min_val
        prob += p

    print(prob / N)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
inf = input().split()
N = int(inf[0])
K = int(inf[1])
ans = 0

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())  # 複数数値入力
ans = 0
num = int(math.log2(k)+1)    # 目が1の時に連続して表にならなくてはいけない数

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

print(ans/n)

Submission status: Accepted

Solution code:
from math import log2, ceil

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

if N <= K:
	lis = [0]*N
	cnt = N + 1
	score = 0
else:
	lis = [0]*(K-1)
	cnt = K
	score = (N-K+1)/N

for i in range(1, cnt):
	lis[i-1] = (1/N) * pow(1/2, ceil(log2(K/i)))
print(sum(lis)+score)

Submission status: Accepted

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

index = []

for i in range(N):
    sum_num = i+1
    cnt = 0
    while sum_num < K:
        sum_num *= 2
        cnt += 1
    index.append(cnt)

ans = 0
for i in range(N):
    ans += ((1/N)*(0.5**index[i]))

print(ans)

Submission status: Accepted

Solution code:
import math

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

v=0
prev_num=0
for i in range(N):
    if i+1==K:
        v+=N-K+1
        break
    KK=K/(i+1)
    num=math.ceil(math.log2(KK))
    if i==0:
        term=0.5**num
    else:
        term*=2**(prev_num-num)
    #print("i,KK,prev_num,num,v",i,KK,prev_num,num,v)
    v+=term
    prev_num=num
v/=N
print(v)

Submission status: Accepted

Solution code:
import math

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def log2(n):
    res = 0
    while n > 1:
        n /= 2
        res += 1
    return res

def ceil(n): # ceiling関数
    if n > int(n):
        return(int(n)+1)
    else:
        return(int(n))

a = []
for i in range(1,N+1):
    k = ceil(log2(K/i))
    if i < K:
        a.append(k)
    else:
        a.append(0)
m = max(a)
s = sum([2**(m-a[i]) for i in range(len(a))])
print(s/(N*(2**m)))

Submission status: Accepted

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

ps=0.0
for i in range(n):
    p=1/n
    score=i+1
    while score < k:
        p*=0.5
        score*=2
    ps+=p

print(ps)

Submission status: Accepted

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

def get_p(nums,k):
    p=1/(2**math.ceil(max(math.log(k/nums,2),0)))
    return p

ans=0
for nums in range(n):
    ans+=get_p(nums+1,k)
    
print("{0:.20f}".format(ans/n))

Submission status: Accepted

Solution code:
import sys
import math
input = sys.stdin.readline

n, k = map(int, input().split())
tmp = float(k)
need = [] # 必要なコイントス回数
while tmp > 1:
    need.append(math.ceil(tmp))
    tmp /= 2
need.append(1)
# print(need)
# # # range(need[i+1], need[i]) の範囲で、コイントスが i 回必要

bunsi = max(0, n-k+1)
bunbo = 1
for i in range(len(need) - 1):
    bunsi *= 2
    bunbo *= 2
    if need[i+1] > n:
        continue
    elif need[i] > n:
        l = len(range(need[i+1], n+1))
    else:
        l = len(range(need[i+1], need[i]))
    bunsi += l

print("{0:.12f}".format(bunsi/bunbo/n))

Submission status: Accepted

Solution code:
# import bisect

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N, K = map(int, input().split())
    ans = 0.0
    for i in range(1, N + 1):
        if i < K:
            num = 0
            while i < K:
                i *= 2
                num += 1
            ans += (1 / (2**num)) * (1 / N)

        else:
            ans += 1 / N

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
t = [[0]*20 for i in range(n)]
count = 0
A = [0 for i in range(n)]
for i in range(n):
    t[i][0] = i+1

for i in range(n):
    for j in range(19):
        t[i][j+1] =t[i][j]*2 
        if t[i][j+1]>=k and t[i][j]<k:
            A[i] = j+1

for i in range(n):
    count = count + (0.5)**A[i]/n

print(count)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p=0
sun=1
answer=0
count=0
for i in range(1,n+1):
  add = 1/n
  ima = i
  while(ima<k):
    ima*=2
    add/=2
  answer+=add
print(answer)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p=0
sun=1
answer=0
count=0
for i in range(1,n+1):
  if i < k:
    if i == 1:
      while(sun<k):
        sun *= 2
        count+=1
    else:
      while(sun>=k):
        sun /= 2
        count-=1
      sun *= 2
      count +=1
    answer+=1/n*1/pow(2,count)
    sun = sun/i*(i+1)
  else:
    answer+=1/n
print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
 
n, k = list(map(int, input().split()))
 
ans = 0
 
"i点の時、k点以上になるためにはlog2(k/i)回連続で表を出す必要がある"
for i in range (1, n + 1):
  if i < k:
    omote = math.ceil(math.log(k/i, 2))
    ans += (1/2) **(omote)
  else :
    ans += 1
print(ans/n)

Submission status: Accepted

Solution code:
from math import (log, ceil)
N, K = map(int,input().split())
total = 0.0
for i in range(1,N+1):
    if i < K:
        a = ceil(log(K/i,2))
        total += 2.0**(-a)
    else:
        total += 1.0
print(total/N)

Submission status: Accepted

Solution code:
import numpy as np
n, k = list(map(int, input().split()))
ndewaru = 0
for p in range(n) :
    if p+1 < k :
        kata = np.floor(np.log2((p+1)/k))
        ndewaru += 2**kata
    else :
        ndewaru += 1
print(ndewaru/n)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
prob = 0
for x in range(1, n + 1):
    value = x
    for y in range(k):
        if (value >= k):
            prob += 1.0/n * (0.5 ** y)
            break
        value *= 2
print(prob)

Submission status: Accepted

Solution code:
def count_doubled(i, n):
	count=0
	while(i<n):
		count+=1
		i = i<<1
	return count

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

result = 0

for i in range(1, N+1):
	result += pow(0.5, count_doubled(i, K))/N

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

Submission status: Accepted

Solution code:
s=list(map(int,input().split()))
a=0
d=0
list = []
for i in range(s[0]):
  c=0
  b=2
  e=i+1
  for l in range(17):
    if e<s[1]:
      e=b*e
      c=c+1
  list.append(c)
for j in range(len(list)):
  d=d+1/(s[0]*2**list[j])
print(d)

Submission status: Accepted

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

percentage = 0

for appear in range(1, N + 1):
	i = 0
	while  K / appear > 2 ** i:
		i += 1
	percentage += (1 / N) * (1/2) ** i
	
print(percentage)

Submission status: Accepted

Solution code:
N,K=(int(x) for x in input().split())
answer = 0
for i in range(N):
  p = 1
  point = i + 1
  while point < K:
#    if point >= K:
#      answer = answer + p / N
#      break
    point = point * 2
    p = p / 2 
    answer = answer + p / N

print(1 - answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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