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())
n_lis=[int(i) for i in range(1,n+1)]
p=float(1/n)
p_lis=[]
for i in range(n):
    if n_lis[i]<k:
        atai=float(k/n_lis[i])
        kaisu=-(-math.log(atai,2)//1) # loop処理しなくてよいので記述が楽
        p_lis.append((1/2)**(kaisu))
    else:
        p_lis.append(1)

print(p*sum(p_lis))

Submission status: Accepted

Solution code:

import numpy as np
n,k=map(int,input().split())
n_lis=[int(i) for i in range(1,n+1)]

p=float(1/n)
p_lis=[]

for i in range(n):
    count=0
    if n_lis[i]<k:
        atai=float(k/n_lis[i])

        for j in range(10000):
            atai=float(atai/2)
            count+=1

            if atai<=1:
                break
        
        p_lis.append((1/2)**(count))
    
    else:
        p_lis.append(1)

print(p*sum(p_lis))

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n, k = map(int, input().split())
ans = 0
for i in range(1, n+1):
    sumv = i
    cnt = 1
    while True:
        if sumv >= k: break
        sumv *= 2
        cnt /= 2
    ans += cnt
print(ans/n)

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
n, k  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

ans = 0

for i in range(1, n+1):
    for ntoss in range(10000000):
        #print(i, ntoss)
        if i * (2 **  ntoss) >= k:
            ans += (1 / n) * ((1 / 2) ** ntoss)
            break
    # n_omote = int(math.ceil(math.log(k, 2)))
print(ans)

Submission status: Accepted

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

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

ans = 0.0
for i in range(1, N+1):
    point = i
    P = 1/N
    while True:
        if point >= K: break
        point *= 2
        P *= 1/2
    ans += P

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# !/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-DiceandCoin.py
#
import math
n, k = map(int, input().split())

# p = (1/n) * (1 - (1/2)**(math.ceil(k/n)))
# if n < k:
#     p -= (1/n) * (1 - (1/2)**(math.ceil(k/n)-n))
# if k <= n:
#     p += (1/n) * (n-k+1)
#
# print(p)
ans = 0
p = 0

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

print(ans)

Submission status: Accepted

Solution code:
from math import * 

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

for i in range(1, N+1):
    if i >= K: c = 0
    else: c = ceil(log2(K/i))
    ans += 1/N * (1/2)**c
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

for i in range(1,N+1):
    if i > K:
        x = 0
    else:
        x = math.log2(K)-math.log2(i)
        x = int(x) if x.is_integer() else int(x) + 1
    ans += (1/N) * pow(1/2,x)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, k = MI()

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

    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    import math
    N, K = [int(item) for item in input().split()]

    res = 0

    for i in range(1,N+1):
        for n in range(int(math.log2(K))+3):
            if i * 2 ** n >= K:
                res += 1/N * 2 ** (-1 * n)
                break

        # print(i, n, res)
    print(res)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

    while p<k:
        p*=2
        cnt+=1
    
    ans+=(1/2)**cnt

print(ans*(1/n))

Submission status: Accepted

Solution code:
def q3():
    import math
    N, K = (int(i) for i in input().split())

    ans = 0
    for n in range(1, N+1):
        if n >= K:
            ans += 1/N  # K以上ならば、確率は1/N
            continue
            
        c = math.ceil(math.log2(K/n))  # 小数繰り上げ
        # print(n, c)
        ans += 1/N * (1/2)**c

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


if __name__ == '__main__':
    q3()

Submission status: Accepted

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

Submission status: Accepted

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

import math

p_k = 0


if N >= K:
    p_N = (N - (K-1))/ N

    for n in range(1, K):
        i = math.ceil(math.log(K/n, 2))
        p_n = (1/N) * ((1/2) ** i)
        p_k += p_n

else:
    p_N = 0

    for n in range(1, N+1):
        i = math.ceil(math.log(K/n, 2))
        p_n = (1/N) * ((1/2) ** i)
        p_k += p_n


p = p_k + p_N
print(p)

Submission status: Accepted

Solution code:
from math import ceil, log2

n, k = [int(x) for x in input().split()]

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

Submission status: Accepted

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

res=0
for i in range(1,n+1):
    cnt=1
    while(i * cnt < k):
        cnt *=2

    res +=  1/cnt

print(res/n)

Submission status: Accepted

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

res=0
for i in range(1,n+1):
    if i >= k:
        res+=1/n
        continue
    
    cnt=1
    while(i * cnt < k):
        cnt *=2

    res += 1/n * 1/cnt

print(res)

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

Solution code:
# import fractions
# import sys
import math
from sys import stdin

n, k = map(int, stdin.readline().rstrip().split())
ans = 0
for i in range(1, n + 1):
    if k / i <= 1:
        ans += (1 / n)
    else:
        ans += (1 / n) / 2 ** (math.ceil(math.log2(k / i)))
print(ans)

Submission status: Accepted

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

import sys
import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, k = mi()
    p = 0
    for point in range(1, n+1):
        if point <= k-1:
            p += 1 / (n * pow(2, math.ceil(math.log(k / point, 2))))
        else:
            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):
    m=0
    while (2**m)*i<k:
        m+=1
    ans+=1/(2**m)
print(ans/n)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

    ans = np / N

    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

Submission status: Accepted

Solution code:
def myAnswer(N:int,K:int) -> int:
   ans = 0
   for n in range(1,N+1):
      total = n
      counter = 0
      while total < K:
         total *= 2
         counter += 1
      ans += 1/N * (1/2)**counter
   return ans

def modelAnswer():
   return
def main():
   N,K = map(int,input().split())
   print(myAnswer(N,K))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
def myAnswer(N:int,K:int) -> int:
   ans = 0
   for n in range(1,N+1):
      total = n
      if(total >= K):
         ans += 1/N
      else:
         counter = 0
         while True:
            total *= 2
            counter += 1
            if(total >= K):
               break
         ans += 1/N * (1/2)**counter
   return ans

def modelAnswer():
   return
def main():
   N,K = map(int,input().split())
   print(myAnswer(N,K))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
def myAnswer(N:int,K:int) -> int:
   ans = 0
   for n in range(1,N+1):
      sub = K - n
      counter = 0
      total = n
      if(total >= K):
         ans += 1/N
         continue
      while True:
         total *= 2
         counter += 1
         if(total >= K):
            break
      ans += 1/N * (1/2)**counter
   return ans

def modelAnswer():
   return
def main():
   N,K = map(int,input().split())
   print(myAnswer(N,K))
if __name__ == '__main__':
   main()

Submission status: Accepted

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

Submission status: Accepted

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

print(s/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
param = list(map(int, input().split()))
n = param[0]
k = param[1]

i = 1
ret = 0
while i <= n:
    cnt = 0
    tmp = k
    while i < tmp:
        tmp = tmp / 2
        cnt += 1
    ret += pow(0.5, cnt)
    i += 1
ret = ret / n
print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,K = map(int,input().split())
p = min(n,K-1)
ans = 0
chk = [1]*(K-1)
k = K
for i in range(16):
  k /= 2
  if k == int(k):
    q = int(k*2-k-1)
  else:
    q = int(k*2-k)
  for i in range(q):
    chk[i] += 1
  if k <= 1:
    break
    
#print(chk)
for i in range(p):
  ans += float(1/(2**chk[i]*n))
  #print(ans)
ans += max(0,(n-K+1)/n)
print(ans)

Submission status: Accepted

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

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

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 itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    # サイコロの出た目が1から考えてみる?
    #    i = 1
    #cnt = 0
    #while i < k:
    #    cnt += 1
    #    i *= 2
    # これじゃだめ 最大から -1...じゃなくて
    # 1から...のほうがいい
    # 逆に少ない方から考える
    # 1から
    ans = 0
    for i in range(1,n+1):
        # 何回かけれるか
        a = 1
        m = i
        while m < k:
            m *= 2
            a *= (1/2)
        ans += a
    ans /= n
    print("%.12f"%(ans))
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from collections import deque
import math
n,k=map(int,input().split())
l=deque()
i=0
while math.ceil(k/(2**i))!=math.ceil(k/(2**(i+1))):
  l.appendleft(math.ceil(k/(2**i)))
  i+=1
l=list(l)
count=len(l)
ans=0
for i in range(1,n+1):
  if i in l:
    count-=1
  ans+=1/(2**count)
print(ans/n)

Submission status: Accepted

Solution code:
from math import ceil
import numpy as np
N,K=map(int, input().split())
#サイコロを振る　１以上K未満→コイン　K以上ゲーム終了、す抜けのかち
#コイン　表なら２倍　裏なら０　０なったら負け
ans=max( (N-K+1),0) /N

#(K-1)/N
# M*(2**x)>=K M:サイコロの目
# x*log(2)>=log(K/M)
lim=min(K-1,N)
for i in range(1,lim+1):
    x=ceil(np.log(K/i)/np.log(2))
    ans+=(1/N)*((0.5)**x)
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
    k = i
    count = 0
    while(k < K):
        k *= 2
        count += 1

    tmp /= 2**count

    ans += tmp
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, n + 1):
    j = 17
    while i * 2 ** j >= k and j >= 0:
        j -= 1
    ans += 1 / n * (1 / 2) ** (j + 1)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

N, K = MAP()
ans = 0
for i in range(1, N + 1):
    # iが出た時
    point = i
    tmp = 1 / N
    cnt = 0
    while point < K:
        tmp *= 1 / 2
        point *= 2
        cnt += 1
    # print(cnt)
    ans += tmp
print(ans)

Submission status: Accepted

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

for i in range(1,n+1):
    j = 1/n
    if i >= k:
        point += j
        continue
    now = i
    count = 0
    while now < k:
        now *= 2
        count += 1
    j *= (1/2)**count
    point += j
    
print(point)

Submission status: Accepted

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

def bisect(x):
    ok = 17
    ng = 0
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if x*(2**mid)>=k:
            ok = mid
        else:
            ng = mid
    return ok

for i in range(1, n+1):
    if i>=k:
        li[0] += n-i+1
        break
    li[bisect(i)] += 1

ans = 0
for i, j in enumerate(li):
    ans += 2**(-i)*j
print(ans/n)

Submission status: Accepted

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

ans=0
for i in range(1,n+1):
  if i>=k:
    ans+=1/n
    continue
  else:
    j=1
    while True:
      if 2**j>=(k/i):
        ans+=(1/n)*0.5**j
        break
      else:
        j+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    import math
    n, k = map(int, input().split())
    ans = 0
    for i in range(1, n+1):
        if k <= i:
            coin = 0
        else:
            coin = math.ceil(math.log(k/i,2))
        ans += (1/n)*(1/(2**coin))
    print(ans)
resolve()

Submission status: Accepted

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    bi = [2**i for i in range(21)]
    ans = 0
    for i in range(1, N+1):
        if K <= i:
            ans += 1/N
        else:
            for j, b in enumerate(bi):
                if K <= b*i:
                    ans += (1/N)*(1/2)**j
                    break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
from math import pi, ceil, floor
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
from bisect import bisect_left, bisect_right, insort_left, insort_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans /= N

print (ans)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc126/tasks/abc126_c
# 最初のサイコロでコインを最大何回降るか決まる
# 最大表が出続ける確率がすぬけくんの勝つ確率
# はじめにサイコロの確率も考慮したい

N, K = read_ints()
mul = 1 / N
ans = 0
for i in ra(1, N + 1):
    n_coin = 0
    prob_win = 1
    while i < K:
        i *= 2
        prob_win /= 2
    ans += prob_win
print(ans * mul)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc126/tasks/abc126_c
n, k = map(int, input().split())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N, K =map(int, input().split())
k = K
bordor = []
Ans = 0
while(K >= 1):
  bordor.append(K)
  K = K / 2
  
for i in range(len(bordor) - 1):
  if bordor[i] <= N:
    Ans += (math.ceil(bordor[i]) - math.ceil(bordor[i + 1])) * (1 / (2 ** (i + 1)))
    
 
  elif bordor[i] > N >= bordor[i + 1]:
    Ans += (N + 1 - math.ceil(bordor[i + 1])) * (1 / (2 ** (i + 1)))
    
if bordor[-1] != 1:
  Ans += 1 / (2 ** len(bordor))

if N >= k:
  Ans += (N - k + 1)
Ans = 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=1/n
 while i<k:i*=2;j/=2
 a+=j
print(a)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
    count=0
    now=i
    if i<k:
        while now<k:
            now*=2
            count+=1
        ans+=0.5**count
    else:
        ans+=1



print(ans/n)

Submission status: Accepted

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

a = 0
for i in range(1, n+1):
    if i >= k:
        a += 1
        continue
    cnt = 0
    score = i
    while score <= k-1:
        score *= 2
        cnt += 1
    a += (1 / 2) ** cnt

ans = (1/n) * a
print(ans)

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
# r = list(map(int, input().split()))
total = 0
if n >= k:
    total += (1/n)*(n-k+1)
#print(total)

for i in range(min(n, k-1)):
    count = 0
    b = i+1
    while k > b:
        b *= 2
        count += 1
    #print(count)
    a = 1/(n*pow(2, count))
    total += a

print(total)

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

Submission status: Accepted

Solution code:
import math

N, K = map(int, input().split(' '))
ans=0
# 1からNまでのどれかがでる、そっから倍々にしてKに
for i in range(1,N+1):
    t=max(0,math.ceil(math.log2(K/i)))
    ans+=(0.5**t)/N
print(ans)

Submission status: Accepted

Solution code:
# C - Dice and Coin

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

ans = 0
for i in range(1, n+1):
    if i >= k:
        ans += 1/n
    else:
        j = i
        c = 0
        while j<k:
            j <<= 1
            c += 1
        ans += (1/n)*pow(0.5, c)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
B=[]
for i in range(N):
  k=i+1
  c=0
  while k<K:
    k*=2
    c+=1
  B.append(N*(2**c))
for i in range(len(B)):
  ans+=1/B[i]
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
if N < K:
    prob = 0
    # サイコロの得点がKより小さい場合
    S = min(N+1, K)
    for i in range(1, S):
        counter = 0
        while True:
            counter += 1
            i *= 2
            if i >= K:
                break
        prob += 0.5 ** counter * (1/N)
    print(prob)
else:
    prob = (N-K+1)/N
    S = min(N+1, K)
    for i in range(1, S):
        counter = 0
        while True:
            counter += 1
            i *= 2
            if i >= K:
                break
        prob += 0.5 ** counter * (1/N)
    print(prob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans / n)