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 math
N,K = map(int,input().split())
ans = 0.0
def f(i):
    k=float(K/i)
    x=0
    while(k>1):
        k /=2
        x+=1
    
    return x

for i in range(1,N+1):
    ans += 1.0/float(float(N)*float(2.0**f(i)))
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

N, K = get_ints()
probs = [0] * max(K + 1, N + 1)
A = len(probs)

for i in range(A - 1, 0, -1):
    if i >= K:
        probs[i] = 1
    elif i * 2 >= K:
        probs[i] = 1 / 2
    else:
        probs[i] = probs[i * 2] / 2

ans = 0
for i in range(1, N + 1):
    ans += probs[i]


ans /= N
print(ans)

Submission status: Accepted

Solution code:
#C
import math
n, k = map(int, input().split())
ans = 0
for i in range(1, n + 1):  #n面ダイスがiを示したとき
    if i<k:
        m = math.ceil(math.log2(k / i))
        # print(i,m)
        ans += 1 / (2**m) / n
        # print(ans)
    else:
        ans += 1 / n
print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N, K = input_nums()
    total_p = 0
    for i in range(1, N+1):
        p = 1/N
        val = i
        cnt = 0
        while val < K:
            cnt += 1
            val *= 2
        total_p += p * (1/2)**cnt
    print(total_p)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ks = [k00]
ns = [0]
k0 = k00+0
n0 = 0
while k0 >1:
    k0 = ((k0*-1)//2)*-1
    n0 += 1
    ks.append(k0)
    ns.append(n0)

for i,j in enumerate(ks):
    if n == j:
        ks1 = [1]
        for k,l in enumerate(ks[i:][:-1]):
            ks1.append(ks[i:][k] - ks[i:][k+1])
        ns1 = ns[i:]
        break
    elif n > j:
        ks1 = [n-j+1]
        for k,l in enumerate(ks[i:][:-1]):
            ks1.append(ks[i:][k] - ks[i:][k+1])
        ns1 = ns[i:]
        break

ans = 0
b1 = 1/n
for i,j in enumerate(ks1):
        ans += (ks1[i])*((1/2)**ns1[i])*(1/n)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

after_explanation()

Submission status: Accepted

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

Submission status: Accepted

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

result = 0
for n in range(1, N + 1):
  point = n
  count = 0

  while point < K:
    point *= 2
    count += 1
  
  result += (1/N) * pow(0.5, count)

print(result)

Submission status: Accepted

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

ret = 0

for i in range(n):
    me = i + 1
    prob = 1
    while me < k:
        prob /= 2
        me *= 2
    ret += (prob / n)

print(ret)

Submission status: Accepted

Solution code:
from math import log2, ceil

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

p = 0
for n in range(1, N + 1):
    if n > K:
        p += 1 / N
        continue
    x = ceil(log2(K) - log2(n))
    # print(x)
    p += 1 / N * pow(0.5, x)
print(p)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

prob = 0.0
for p in range(1, N+1):
    c_prob = 1/N
    while p <= K-1:
        p *= 2
        c_prob *= 1/2
    prob += c_prob

print(prob)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import math

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:
        ans += 1/(N*2**math.ceil(math.log2(K/i)))
print(ans)

Submission status: Accepted

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

ans = 0

if N >= K:
    ans += (N - K + 1) / N
    L = K-1
    #print(N-K+1)
else:
    L = N
#print(ans)

rate = 0
for i in range(1,L+1,1):
    #print(i)
    score = i
    c = 0
    
    while score < K:
        score = score * 2
        c += 1
    r = 2** c
    #print(c)
    rate += 1/r
    
    #print(ans)
ans += (1/N) * rate

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n):
  s=i+1
  c=0
  while s<=k-1:
    c+=1
    s*=2
  a+=1/n*(1/2**c)

print(a)

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
now=k
cnt=0 #割った回数
ans=max(0,n-k+1)
while now>=1:
    a=now/2
    b=math.ceil(a) #最小値
    if now!=int(now):
        c=int(now) #最大値
    else:
        c=int(now)-1
    cnt+=1
    if b>min(k-1,n): #調べる最大値(K-1かNの小さいほう)が最小値より大きいとき
        now=a
        continue
    elif c>min(k-1,n): #最大値より小さいとき
        c=min(k-1,n) #最大値を補正
    ans+=1/(2**cnt)*(c-b+1)
    now=a
    if now==1:
        break
print(ans/n)

Submission status: Accepted

Solution code:
c=0
def doublet(n,f):
    global c
    if n<f:
        c=c+1
        return doublet(2*n,f)
    else:
        return c
num,k=input().split()
num=int(num)
k=int(k)
#k=eval(input())
if (num>=1 and num<=10**5) and (k>=1 and k<=10**5):
    sum_power=0.0
    for i in range(1,(num+1),1):
        count=doublet(i,k)
        p=pow(2,count)*num
        sum_power=sum_power+(1/p)
        c=0
    print(sum_power)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    for j in range(100000):
        if i * (2 ** j) >= K:
            ans += (1 / N) * (0.5) ** j
            break
print(ans)

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
sumlist = []
for i in range(1,n+1):
  point = i
  if point <= k-1:
    s = math.log(k/i,2)
    if s == int(s):
      sumlist.append((1/2)**(int(s)))
    else:
      sumlist.append((1/2)**(int(s)+1))
  else:sumlist.append(1)
print(round(sum(sumlist)/n,10)-10**(-10))

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
temp=0
for i in range(1,n+1):
  if k<i:temp+=1
  else:temp+=2**(-math.ceil(math.log(k/i,2)))
  
print(temp/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 * 2**cnt < K:
    cnt += 1
  ans += 1 / N * (0.5)**cnt
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
i=0
pre = 0
tmp = 0
if n >= k:
    ans += (n-k+1)
    pre = k
    i = 1
    tmp = (pre+1)//2
else:
    pre = n+1
    tmp = k
    i=0
    while n < tmp:
        tmp = (tmp+1)//2
        i+=1
    ans += (pre-tmp)*((0.5)**i)
    pre = tmp
    i+=1
    tmp = (pre+1)//2
while pre != tmp:
    # i回コインで面出す必要あり 
    ans += (pre-tmp)*((0.5)**i)
    pre = tmp 
    i+=1
    tmp = (pre+1)//2
print(ans/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = []
for i in range(1, N+1):
    tmp = i
    cnt = 0
    while tmp<K:
        tmp *= 2
        cnt += 1
    A.append(cnt)
pro = []
for i in A:
    pro.append(1/N*(1/2)**i)
print(sum(pro))

Submission status: Accepted

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

for i in range(1,N+1):
    p=1
    sc=i
    cnt=0
    while 1<=sc<=K-1:
        cnt +=1
        p /=2
        sc *=2
    #print(i,cnt,p/N)
    ans += p/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 < K:
    i *= 2
    cnt += 1
  p = N * pow(2,cnt)
  ans += 1 / p
  
print(ans)

Submission status: Accepted

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

for i in range(1,n+1):
    score = i
    rate = 1/n
    while(score <= k-1):
        rate *= (1/2)
        score  *= 2
    rate_total.append(rate)

print(sum(rate_total))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
L = [0]*N
for i in range(min(K-1,N)):
  n = 1
  while (i+1)*(2**n) < K:
    n = n+1


  L[i] = (1/2)** n

if N >= K:
  for j in range(K-1,N):
    L[j] = 1

print(sum(L)/N)

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))
  ans += min(2**-x,1)
  #print(ans,x)
print(ans/N)

Submission status: Accepted

Solution code:
N, K =map(int, input().split())
win = 1
cnt = 0
 
def DFS(i, win):
    if(i < K):  # Kを超える得点にならない限り、コインで表になり続ける必要がある
        win *= 0.5 # 1枚追加で表
        i *= 2 # 特典は2倍
        return DFS(i, win) # それが繰り返される
    else:
        return win
    
for i in range(1, N+1): # 1からNまでのケースで繰り返す
    cnt += DFS(i, 1/N)
print(cnt)

Submission status: Accepted

Solution code:
N, K =map(int, input().split())
win = 1
cnt = 0

def DFS(i, win):
    if(i < K):
        win *= 0.5
        i *= 2
        return DFS(i, win)
    else:
        return win
    
for i in range(1, N+1):
    cnt += DFS(i, 1/N)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import numpy as np
import math

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
N, K = map(int, raw_input().split())

ans = 0
for i in range(1, N+1):

    mi = np.log2(1.0*K/i)

    mi = max(mi,0)
    mi = math.ceil(mi)
    ans += (1.0/2)**mi

ans = ans/N
print ans

Submission status: Accepted

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

point=0
ans=0
toss_cnt=0

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

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

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n, k = input_list()
  ans = 0
  for i in range(1, n+1):
    t = 1.0
    while i < k:
      i *= 2
      t /= 2
    ans += t
  print(ans/n)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Accepted

Solution code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    ret = 0
    for n in range(1, N+1):
        t = 1
        while n * t < K:
            t *= 2
        ret += 1 / t

    print(ret / N)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def main():
    n, k = [int(i) for i in input().split()]

    res = 0
    for i in range(n):
        ini = i + 1
        succ_req = math.ceil(math.log2(math.ceil(k / ini)))
        prob = (0.5 ** succ_req) / n
        res += prob
    print(res)

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:
        n = math.ceil(math.log2(K/i))
        ans += 2 ** (-n)
ans /= N
print(ans)

Submission status: Accepted

Solution code:
def solve():
    N, M = map(int, input().split())
    l = []
    for i in range(1, N+1):
        a = i
        c = 0
        while a < M:
            a *= 2 
            c += 1
        b = 1 if c == 0 else (0.5)**c
        l.append(b * (1/N))
    return sum(l)

print(solve())

Submission status: Accepted

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

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

print(p)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()


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

print(prob)

Submission status: Accepted

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

ans = max((n-k+1)/n, 0)
for i in range(1, min(k, n+1)):
  j = 1
  while i*(2**j) < k:
    j += 1
  ans += (1/n) * (1/2**j)

print(ans)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n,k = map(int,input().split())

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

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = [0] * n

for i in range(1, n+1):
    score = i
    cnt = 0
    while score < k:
        score *= 2
        cnt += 1
    if cnt==0:
        proba = 1.0
    else:
        proba = (1/2)**cnt
    p[i-1] = proba

ans = 0
for pp in p:
    ans += (1/n)*pp

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

print(p/N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
def two(N,K):
  n = 0
  while N<K:
    N*=2
    n+=1
  return n
res = 0
for i in range(1,N+1):
  res += (1/N)*(1/2)**two(i,K)
print(res)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations, permutations, product, combinations_with_replacement, accumulate
from heapq import heapify, heappop, heappush, heappushpop
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from math import sqrt, log, floor, ceil, factorial, cos, sin, pi #, gcd
from fractions import gcd
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
LINF = 2**63-1
NIL = -LINF
MOD = 10**9+7
MGN = 4
def AST(exp: bool, msg: str = ""): assert exp, msg
def TAST(exp: bool, msg = ""):
    if exp is False: print("TAssertionError:", msg)
    while exp is False:
        pass
def EPR(msg): print(msg, file=sys.stderr)
def II(): return int(input())
def IF(): return float(input())
def IS(): return input().replace('\n', '')
def ILCI(n: int): return [II() for _ in range(n)]
def ILCF(n: int): return [IF() for _ in range(n)]
def ILI(): return list(map(int, input().split()))
def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)]
def ILF(): return list(map(float, input().split()))
def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)]
def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst))
def DEC(lst: list): return list(map(lambda x: x-1, lst))
def INC(lst: list): return list(map(lambda x: x+1, lst))


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

    ans = 0.0
    for i in range(1,N+1):  # サイコロの出た目
        scr = i  # 現在のスコア
        pb = 1.0  # 現在のスコアとなる確率
        win = True  # 勝ち続けているか
        while True:
            if K <= scr:  # 勝ち
                break
            elif 0 < scr < K:
                scr *= 2
                pb *= 0.5
            else:  # 負け
                TAST(False, "ここには来ない")
                scr = 0
                win = False
                break
        if win:
            ans += pb / N

    print("{:.12}".format(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import combinations, permutations, product, combinations_with_replacement, accumulate
from heapq import heapify, heappop, heappush, heappushpop
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from math import sqrt, log, floor, ceil, factorial, cos, sin, pi #, gcd
from fractions import gcd
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
LINF = 2**63-1
NIL = -LINF
MOD = 10**9+7
MGN = 4
def AST(exp: bool, msg: str = ""): assert exp, msg
def TAST(exp: bool, msg = ""):
    if exp is False: print("TAssertionError:", msg)
    while exp is False:
        pass
def EPR(msg): print(msg, file=sys.stderr)
def II(): return int(input())
def IF(): return float(input())
def IS(): return input().replace('\n', '')
def ILCI(n: int): return [II() for _ in range(n)]
def ILCF(n: int): return [IF() for _ in range(n)]
def ILI(): return list(map(int, input().split()))
def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)]
def ILF(): return list(map(float, input().split()))
def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)]
def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst))
def DEC(lst: list): return list(map(lambda x: x-1, lst))
def INC(lst: list): return list(map(lambda x: x+1, lst))


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

    ans = 0.0
    for i in range(1,N+1):  # サイコロの出た目
        scr = i  # 現在のスコア
        pb = 1.0  # 現在のスコアとなる確率
        win = True  # 勝ち続けているか
        while True:
            if K <= scr:  # 勝ち
                break
            elif 0 < scr < K:
                scr *= 2
                pb *= 0.5
            else:  # 負け
                TAST(True, "ここには来ない")
                scr = 0
                win = False
                break
        if win:
            ans += pb / N

    print("{:.12}".format(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

p = 0
for score in range(1,n+1):
    if k <= score:
        # コインを振る必要が無い場合
        p += 1
    else:
        # コインを振る必要がある場合
        # 連続で何回表を連続する必要があるか？
        x = 1
        while(True):
            if (2**x) * score >= k:
                break
            else:
                x += 1
        p += (0.5) ** x

print(p/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from itertools import combinations, permutations, product, combinations_with_replacement, accumulate
from heapq import heapify, heappop, heappush, heappushpop
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from math import sqrt, log, floor, ceil, factorial, cos, sin, pi #, gcd
from fractions import gcd
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
LINF = 2**63-1
NIL = -LINF
MOD = 10**9+7
MGN = 4
def AST(exp: bool, msg: str = ""): assert exp, msg
def TAST(exp: bool, msg = ""):
    if exp is False: print("TAssertionError:", msg)
    while exp is False:
        pass
def EPR(msg): print(msg, file=sys.stderr)
def II(): return int(input())
def IF(): return float(input())
def IS(): return input().replace('\n', '')
def ILCI(n: int): return [II() for _ in range(n)]
def ILCF(n: int): return [IF() for _ in range(n)]
def ILI(): return list(map(int, input().split()))
def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)]
def ILF(): return list(map(float, input().split()))
def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)]
def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst))
def DEC(lst: list): return list(map(lambda x: x-1, lst))
def INC(lst: list): return list(map(lambda x: x+1, lst))


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

    ans = 0.0
    for i in range(1,N+1):  # サイコロの出た目
        scr = i  # 現在のスコア
        pb = 1.0  # 現在のスコアとなる確率
        if K <= scr:  # 最初から勝っていたら
            ans += pb/N
            continue

        # n 回コインを投げて勝ち続けると得点は
        # scr * 2**n
        # 勝ちとなるのは
        # scr * 2**n >= K
        n = ceil(log(K/scr, 2))
        
        ans += pow(0.5, n) / N

    print("{:.12}".format(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import combinations, permutations, product, combinations_with_replacement, accumulate
from heapq import heapify, heappop, heappush, heappushpop
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from math import sqrt, log, floor, ceil, factorial, cos, sin, pi #, gcd
from fractions import gcd
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
LINF = 2**63-1
NIL = -LINF
MOD = 10**9+7
MGN = 4
def AST(exp: bool, msg: str = ""): assert exp, msg
def TAST(exp: bool, msg = ""):
    if exp is False: print("TAssertionError:", msg)
    while exp is False:
        pass
def EPR(msg = ""): print(msg, file=sys.stderr)
def II(): return int(input())
def IF(): return float(input())
def IS(): return input().replace('\n', '')
def ILCI(n: int): return [II() for _ in range(n)]
def ILCF(n: int): return [IF() for _ in range(n)]
def ILI(): return list(map(int, input().split()))
def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)]
def ILF(): return list(map(float, input().split()))
def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)]
def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst))
def DEC(lst: list): return list(map(lambda x: x-1, lst))
def INC(lst: list): return list(map(lambda x: x+1, lst))


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

    ans = 0.0
    for i in range(1,N+1):
        scr = i  # 現在のスコア
        pb = 1.0  # 現在のスコアとなる確率
        win = True  # 勝ち続けているか
        while True:
            if K <= scr:  # 勝ち
                EPR(scr)
                break
            elif 0 < scr < K:
                scr *= 2
                pb *= 0.5
            else:  # 負け
                scr = 0
                win = False
                break
        if win:
            ans += pb / N

    print("{:.12}".format(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

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

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

    print((1/N)*sum(cntlist[1:]))

resolve()

Submission status: Accepted

Solution code:
import math

n, k = map( int, input().split())
 
ans = 0
for i in range(1, n + 1):
  a = max( 0 , math.ceil(math.log( k / i, 2 )))
  ans += ( 1 / n ) * ( 0.5 ** a )
print(ans)