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

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, K = inm()


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


print(solve())

Submission status: Accepted

Solution code:
def f(n):
    k = 0
    while n*2**k<K:
        k += 1
    return k
N,K = map(int,input().split())
if K<=N:
    P = (N-K+1)/N
    for i in range(1,K):
        P += 2**(-f(i))/N
else:
    P = 0
    for i in range(1,N+1):
        P += 2**(-f(i))/N
print(P)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
ans = 0
for i in range(1,n+1):
    prob = 1
    base = i
    while base < k:
        base *= 2
        prob /= 2
    ans += prob
print(ans/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-1:
        cnt += 1
        i *= 2
    ans += 1/n * (1/2) **cnt
print(ans)

Submission status: Accepted

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

ans = 0
# サイコロの目は1,2,...,N（等確立）
for i in range(1, n + 1):

    cnt = 0
    temp = i
    # cnt = 何回2倍したらk超えるか
    while temp < k:
        temp *= 2
        cnt += 1
    # サイコロでその目が出る確率は1/n
    # そこから表を出し続けてk越える確率は(1/2)**cnt
    ans += (1 / n) * ((1 / 2)**cnt)
print(ans)

Submission status: Accepted

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

ans = 0
# サイコロの目は1,2,...,N（等確立）
for i in range(1, n + 1):

    cnt = 0
    temp = i
    # cnt = 何回2倍したらk超えるか
    while temp < k:
        temp *= 2
        cnt += 1
    # サイコロでその目が出る確率は1/n
    # そこから表を出し続けてk越える確率は(1/2)**cnt
    ans += (1 / n) * ((1 / 2)**cnt)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
l = []
logk = math.log2(k)
for i in range(1, n + 1):
    p = math.ceil(logk - math.log2(i))
    p = p if p >= 0 else 0
    l.append(p)
maxl = max(l)
l = list(map(lambda x: 2**(maxl-x), l))
print(sum(l)/(n*2**maxl))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def f(n):
    cnt = 0
    while n != 0:
        n //= 2
        cnt += 1
    return max(cnt,1)

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

cnt = f(k)
ans = 0
num = n
for i in range(n):
    while cnt != 0 and k / (i+1) <= 2**(cnt - 1):
        cnt -= 1
    ans += (1 / num)*math.pow(0.5,cnt)
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    # 等間隔のダイスとコインなので、dの目ごとの勝利確率をだし、平均すると答。
    n, k = map(int, input().split())

    pro = 0
    for i1 in range(1, n + 1):
        if i1 >= k:
            pro += 1
        else:
            pro_t = 1
            while i1 < k:
                pro_t /= 2
                i1 *= 2
            pro += pro_t
    r = pro / n
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def INT():
    return int(input())

def MI():
    return map(int, input().split())

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

N, K = MI()
p = 0

for i in range(1, N + 1):
    p_i = 1 / N
    ex = 0
    
    if i < K: 
        while 1:
            ex += 1
            if i * pow(2, ex) >= K:
                break
    
    p += p_i * (1 / 2)**ex
    
print(p)

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    num_success = max(0,math.ceil(math.log2(K / i)))
    ans += (1 / 2) ** num_success
   
print(ans / N)

Submission status: Accepted

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



if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(ans / n)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(1, n+1):
    pp = 1/n;
    x = 1
    while i * x < k:
        x *= 2 
        pp *= 0.5
    p += pp
print(p)

Submission status: Accepted

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

Submission status: Accepted

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

if n >= k:
    ans = (n-k+1)
else:
    ans = 0

for i in range(1, min(n+1, k)):
    cnt = 0
    score = i
    while score < k:
        score *= 2
        cnt += 1
    ans += pow(1/2, cnt)

ans /= n
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

#まず、nがk以上だった場合、勝ちになるので、① n-k+1/n
#k-1 => 得点 >1の場合、コインを投げ、表を出し続け、k以上に出す確率
#k-1=> k/2（切り上げ）に関しては、１回表を出すから 1/2 (1乗）
#k/2(切り捨て）からk/4（切り上げ）に関しては、1/2の二乗
#print(int(math.log2(n))+1)
if n>=k:
  ans=n-k+1
  for i in range(1, k):
    ans+=(1/2)**(math.ceil(math.log2(k/i)))
else:
  ans=0
  for i in range(1, n+1):
    ans+=(1/2)**(math.ceil(math.log2(k/i)))
print(ans/n)

Submission status: Accepted

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

def main(n,k):
    ans=0
    for i in range(1,n+1):
        p=1/n
        point=i
        while(point<k):
            point*=2
            p/=2
        #print(p)
        ans+=p
    return ans

if __name__=='__main__':
    n,k=readinput()
    ans=main(n,k)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=[1]
for k in range(17):
    P.append(P[-1]/2)

Q=0
for i in range(1,N+1):
    u=0
    x=i
    while x<K:
        u+=1
        x*=2
    Q+=P[u]

print(Q/N)

Submission status: Accepted

Solution code:
from fractions import Fraction
N , K = list(map(int,input().split()))
denom_list = []
Z=0


def detame_keisan( N , K , i ):
    kijun = K
    score = i
    count = 0
    
    while score < kijun:
        count += 1
        score = ( score *  2 )
    return N * (2 ** count)

for i in range( 1,N+1 ):
    X = detame_keisan( N , K , i)
    denom_list.append( X )

for item in denom_list:
    #Z += 1/item
    Z += Fraction(1, item)
#print( Z)
print( float( Z ))

Submission status: Accepted

Solution code:
from math import log2, ceil
n, k = map(int, input().split())
prob = [0.5**max(ceil(log2(k / i)), 0) for i in range(1, n + 1)]
print(sum(prob) / n)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

proba = 0.0

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

    while i*(2**exp) < k:
        exp+=1

    proba += (1/n) * (0.5**exp)

print(proba)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import Fraction

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

number = []
count = 0
result_a = 0

for i in range(1,N+1):
    while i <= K-1:
        i *= 2
        count += 1
    count = 2**count
    number.append(count*N)
    count = 0

for j in range(N):
    number[j] = Fraction(1,number[j])

for k in range(N):
    result_a += number[k]

result_b = float(result_a)
print(result_b)

Submission status: Accepted

Solution code:
from fractions import Fraction

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

case = []
number = []
count = 0
result_a = 0

for i in range(N):
    case.append(i+1)

for j in range(N):
    while case[j] <= K-1:
        case[j] *= 2
        count += 1
    count = 2**count
    number.append(count*N)
    count = 0

for k in range(N):
    number[k] = Fraction(1,number[k])

for l in range(N):
    result_a += number[l]

result_b = float(result_a)
print(result_b)

Submission status: Accepted

Solution code:
import math
N, K = list(map(int, input().split()))
res = 0
for i in range(1, min(N + 1, K)):
    res += math.pow(0.5, math.ceil(math.log2(math.ceil(K / i)))) / N
print(f'{res + max(0, (N - K + 1) / N):.10f}')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import ceil, log2
n, k = map(int, input().split())
p = 1 / n
res = max(0, p*(n-k+1))
for i in range(1, min(n+1, k)):
    res += p*(0.5**ceil(log2(k/i)))
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools


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


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math
import itertools


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


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(1,a+1):
    c = i
    while c < b:
        c = c*2
        ans += 1
    p += 1/2**ans
    ans = 0

print(p/a)

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

Submission status: Accepted

Solution code:
from math import *
N,K=list(map(int,input().split()))
out=0
for n in range(1,N+1):
    if n>=K:
        out+=1/N
    else:
        out+=(1/N)*(1/2)**(ceil(log(K/n,2)))
print(out)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil, log2

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

rate = 0
for i in range(1, n + 1):
    cnt = 0
    if i < k:
        cnt = ceil(log2(k) - log2(i))
    rate += 1 / n * 0.5 ** cnt

print(rate)

Submission status: Accepted

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

ans=0

for x in range(1,n+1):
  l=x
  if l>=k:
    ans+=(1/n)
  else:
    test=0
    while l<k:
      l=l*2
      test+=1
     
    p=(1/2)**test
    ans+=(1/n)*p
    
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, k = [int(x) for x in input().split()]
    ans = 0
    for i in range(1, n + 1):
        x = 1 / n
        score = i
        while score < k:
            score *= 2
            x /= 2
        ans += x
    print(ans)


    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""


"""

Submission status: Accepted

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

Submission status: Accepted

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

result = 0.0
for i in range(n):
  score = i + 1
  rate = 1.0
  while(score < k):
    rate = rate / 2
    score = score * 2
  result += rate

result = result / n
print(result)

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,K = LI()

prob = []
for i in range(1,N+1):
    if i >= K:
        prob.append(1)
    else:
        a = 0
        while i*2**a < K:
            a += 1
        prob.append(1/2**a)

print(sum(prob)/N)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

dp = [1.0] * (200_010)
for n in range(K - 1, 0, -1):
    dp[n] = 0.5 * dp[2 * n]

print(sum(dp[1:N + 1]) / N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 12, 2020 15:02:31 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


import bisect
from sys import stdin
input = stdin.readline


def least(n, k):
  return bisect.bisect_left(list(map(lambda x: n*2**x, range(20))), k)


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

  P = 0
  for i in range(1, N+1):
    if 0 < i < K:
      P += (1/N) * (0.5)**least(i, K)
    if K <= i:
      P += (1/N)

  print(P)


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

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-1:
        i=2*i
        cnt+=1
        
    ans+=(1/2)**cnt

ans/=n

print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

# def my_pow(base, n, mod):
#     if n == 0:
#         return 1
#     x = base
#     y = 1
#     while n > 1:
#         if n % 2 == 0:
#             x *= x
#             n //= 2
#         else:
#             y *= x
#             n -= 1
#         x %= mod
#         y %= mod
#     return x * y % mod

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):
    a = max([math.ceil((math.log2(k/i))),0])
    p += 1/(n*(2**a))

print(p)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
P = 0
for i in range(1,N+1):
  j = 0
  t = 1
  while t>0:
    t = K-i*2**j
    j = j+1
  P = P+(1/N)*(1/2)**(j-1)
print(P)

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
import math

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

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

    ans = 0
    for i in range(1, n+1):
        t = 0
        while i < k:
            i *= 2
            t += 1
        ans += 0.5 ** t
    ans /= n
    print(f"{ans:.12f}")
    return

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    n, k = map(int, input().split())
    ans = 0
    for i in range(1, n+1):
        x = 0
        while i < k:
            x += 1
            i *= 2
        ans += (1 / n) * (1 / 2)**x
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
total=0
for i in range(1,N+1):
    if i>=K:
        total+=1
    for j in range(20):
        
        if (2**j)*i<K<=(2**(j+1))*i:
            a=j+1
            total+=(1/2)**a
            break

print((1/N)*total)

Submission status: Accepted

Solution code:
import math

n, k  = map(int, input().split())
if k<=n:
    ans = 0
    for i in range(1, k):
        m = math.ceil(math.log2(k/i))
        ans+=1/pow(2, m)
    ans/=n
    ans += (n-k+1)/n
    print(ans)
else:
    ans = 0
    for i in range(1, n+1):
        m = math.ceil(math.log2(k/i))
        ans+=1/pow(2, m)
    ans/=n
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))

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

ans = float(0)

if K <= N:
    ans += (N-K+1)/N
    X = K
else:
    X = N+1

for i in range(1,X):
    tmp = float(1/N)
    tmp2 = i
    while tmp2 < K:
        tmp2 *= 2
        tmp /= 2
    ans += tmp

print(ans)

Submission status: Accepted

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

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

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

print(ans/N)

Submission status: Accepted

Solution code:

import math

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
Pd = 1 / N
Pc = 0.5
ans = []
def f(i):
  P = Pd
  while(i<K):
    P = P * Pc
    i = 2 * i
  return P

for j in range(1,N+1):
  ans.append(f(j))
  
print(sum(ans))

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,k = readInts()

x = 0

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

print(x/n)

Submission status: Accepted

Solution code:

def solve():
    scr_ini = list(range(1,N+1))
#    print(scr_ini)
    cnt = [0] * N
    ans = [0] * N
    for i in range(N):
        j = 0
        while scr_ini[i]*2**j < K:
            cnt[i] = j
            j += 1
        if scr_ini[i]*2**j >= K:
            cnt[i] = j
            ans[i] = (1/N) * 0.5**j
#    print(cnt) 
#    print(ans)
    print(sum(ans))

if __name__ == "__main__":
    N,K = list(map(int, input().split()))
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

scores = []
max_patterns = 0

for dice in range(1, N + 1):
    score = dice
    coin_counts = 0
    while score < K:
        score *= 2
        coin_counts += 1
    patterns = 2 ** coin_counts
    max_patterns = max(patterns, max_patterns)
    lose = patterns - 1
    win = 1
    scores.append((win, lose, patterns))

total_win = 0
total_lose = 0
for win, lose, patterns in scores:
    ratio = max_patterns // patterns
    total_win += win * ratio
    total_lose += lose * ratio

win_ratio = total_win / (total_win + total_lose)
print(win_ratio)

Submission status: Accepted

Solution code:
import math
N,K  = (int(x) for x in input().split())
Win  = list(max(math.ceil(math.log2(K/X)),0) for X in range(1,N+1))
Prob = sum(1/(N*pow(2,X)) for X in Win)
print(Prob)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    p = 1
    j = 0
    while i*pow(2,j) < k:
        j += 1
    ans += pow(0.5,j)/n
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
    now = i
    while now < K:
        now *= 2
        tmp /= 2
    
    ans += tmp
        
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n,k=map(int,input().split())
odd = 0
for i in range(1,n+1):
    a=0
    while k > i*2**a:
        a+=1
    odd += 2**-a
print(odd/n)

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:
    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 decimal
n,k=map(int,input().split())
num1=1
num2=0
for i in range(20):
    if num1>=k:
        break
    num1*=2
    num2+=1
num=n*(2**num2)
num1=num2
num3=0
for i in range(1,n+1):
    if i*(2**(num2-1))>=k:
        num2-=1
    if i>=k:
        num3+=2**num1
    else:
        num3+=2**(num1-num2)
print(decimal.Decimal(num3/num))

Submission status: Accepted

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

ans_sum=0#確率合計

for i in range(1,N+1):
    num=i#現在の数字格納用
    ans=1/N #Nの目が出る確率
    while num<K:
        num*=2
        ans/=2
    #print(ans)
    ans_sum+=ans
print(ans_sum)

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:
    t = math.log10(k/i)/math.log10(2)
    if t == int(t):
      ans += 1/(2**t)
    else:
      ans += 1/(2**(int(t+1)))
  else:
    ans += 1
  
print(ans/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import Fraction
import math

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

p = Fraction(0, 1)
if K == 1:
    # 確定勝利
    print("1.0")
else:
    for i in range(1, N+1):
        # 出目i
        if i >= K:
            p += Fraction(1, N)
        else:
            n_win = math.ceil(math.log2(K / i))
            p += Fraction(1, 2**n_win * N)
    print(float(p))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
for i in range(1, n+1):
    sum = 1 / n
    jd = i
    while jd < k:
        sum *= 0.5
        jd *= 2
    ans += sum
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*2**c<k):
    c+=1
  ans+=1/n*(0.5**c)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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