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                                                                                                                                                         
                                                                                                                                                                    
def ci(n,k):                                                                                                                                                        
    #p ci>k                                                                                                                                                         
    a = n-k+1                                                                                                                                                       
    if(a<0):                                                                                                                                                        
        return 0                                                                                                                                                    
    else:                                                                                                                                                           
        return float(a/n)                                                                                                                                           
                                                                                                                                                                    
def coin(n,k):                                                                                                                                                      
    a = k/n                                                                                                                                                         
    if(a<1):                                                                                                                                                        
        return 0                                                                                                                                                    
    else:                                                                                                                                                           
        m = math.log(a)/math.log(2)                                                                                                                                 
        #print(m)                                                                                                                                                   
        #print(int(m)+1)                                                                                                                                            
        return(int(math.ceil(m)))                                                                                                                                   
                                                                                                                                                                    
def p_coin(n):                                                                                                                                                      
    return math.pow(0.5, n)                                                                                                                                         
                                                                                                                                                                    
def sumP3(n,k):                                                                                                                                                     
    a = 0                                                                                                                                                           
    for i in range(1, k):                                                                                                                                           
        if i>n :                                                                                                                                                    
            break                                                                                                                                                   
        #print(i,k)                                                                                                                                                 
        #print(p_coin(coin(i,k)))                                                                                                                                   
        a = a + (1/N[0])*p_coin(coin(i,k))                                                                                                                          
    return a                                                                                                                                                        
                                                                                                                                                                    
N = input().split()                                                                                                                                                 
N = [int(i) for i in N]                                                                                                                                             
#print(N)                                                                                                                                                           
#print(ci(N[0], N[1]))                                                                                                                                              
p1 = ci(N[0], N[1])                                                                                                                                                 
p2 = 1-p1                                                                                                                                                           
p3 = sumP3(N[0], N[1])                                                                                                                                              
print('{:.10g}'.format(p1+p3))

Submission status: Accepted

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

pow2 = [2**i for i in range(50)]
#print(pow2[-1])
ans = 0

for i in range(1,N+1):
    for j in range(len(pow2)):
        if K <= i*pow2[j]:
            #print(j)
            ans += 1/pow2[j]
            break
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, score = 0, i
  while score < K:
    score *= 2
    cnt += 1
  ans += (1.0/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, score = 0, i
  if i >= K:
    ans += 1.0/N
  else:
    while score < K:
      score *= 2
      cnt += 1
    ans += (1.0/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=i
  pro=1
  while cnt<K:
    cnt*=2
    pro/=2
  pro/=N
  #print(pro)
  ans+=pro
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

def main():
    N,K = cin.mapInt()
    ans = 0
    for i in range(1,N + 1):
        ans += (1.0 / Math.nearPow2(math.ceil(K / i)))
    ans /= N
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(1, N+1):
        ten = i
        ratio = 1.0 / N
        while ten < K:
                ten *= 2
                ratio *= 0.5
        sum_ratio += ratio

print(sum_ratio)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline


# def eprint(*args, **kwargs):
#     print(*args, file=sys.stderr, **kwargs)


import math
# import string
# import fractions
from fractions import Fraction
# from fractions import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))

# import re
# import array
# import copy
# import functools
# import operator

# import collections
# import itertools
# import bisect
# import heapq

# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace

# from queue import PriorityQueue as pq

# # from itertools import accumulate
# # from collections import deque
# import random


def crange(a, b, i):
    return range(a, b + 1, i)


def main():
    n, k = map(int, input().split())
    p12 = Fraction(1, 2)
    ans = 0
    for i in crange(1, n, 1):
        if i >= k:
            ans += 1
        else:
            ans += p12**(math.ceil(math.log(Fraction(k, i), 2)))
    print(float(Fraction(ans, n)))
    # eprint("Fraction(ans,n) ", end=": ")
    # eprint(Fraction(ans, n))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
import sys
input = sys.stdin.readline


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

    result = 0
    if n < k:
        for i in range(1, n + 1):
            x = math.ceil(math.log(k / i, 2))
            result += (1 / n) * (0.5 ** x)
    else:
        for i in range(1, k):
            x = math.ceil(math.log(k / i, 2))
            result += (1 / n) * (0.5 ** x)
        result += (n - k + 1) / n
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
import sys
input = sys.stdin.readline


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

    result = 0
    if n < k:
        for i in range(1, n + 1):
            x = math.ceil(math.log(k / i, 2))
            result += (1 / n) * (0.5 ** x)
    else:
        for i in range(1, k):
            x = int(math.log(k / i, 2)) + 1
            result += (1 / n) * (0.5 ** x)
        result += (n - k + 1) / n
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
ans = 0
for i in range(1,a+1):
  c = 0
  bai = b/i
  while bai > 1:
    bai /= 2
    c += 1
  ans += 1/(2**c)
print(ans/a)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
ans = 0
for i in range(1, N + 1):
    tmp = 1.0 / N
    now = i
    while now < K:
        now *= 2
        tmp /= 2
    ans += tmp

print(ans)

Submission status: Accepted

Solution code:
import math

def solve(n, k):
    f = lambda i: 1 / 2 ** math.ceil(math.log2(k / i))
    return sum(1 / n * (1 if k <= i else f(i)) for i in range(1, n + 1))

_n, _k = map(int, input().split())
print(solve(_n, _k))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
total_prob = 0
for i in range(1, n+1):
  dice_count = 0
  while (i << dice_count) < k:
    dice_count += 1
  
  total_prob += (1 / n) * (0.5 ** dice_count)
  
print(round(total_prob, 12))

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

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

iniarray = np.arange(1,N+1)
mask1 = iniarray < K
mask2 = 1 - mask1
prob_array = 1/2**np.ceil(np.log2(float(K)/iniarray))
ans = (prob_array * mask1 + mask2).sum() / float(N)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
N, K = [int(i) for i in stdin.readline().rstrip().split()]
output = 0
for n in range(1, N + 1):
    first_score = n
    now_score = n
    front_count = 0
    while now_score < K:
        front_count += 1
        now_score *= 2
    output += ((1/2) ** front_count) / N
print(output)

Submission status: Accepted

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

import math
# i*(2^x) >= k を満たす x を求める
ans = 0
for i in range(1,n+1):
    x = -(-math.log2(-(-k//i))//1)
    ans += 0.5**x
print(ans/n)

Submission status: Accepted

Solution code:
import os, sys, re, math

(N, K) = [int(n) for n in input().split()]

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

Submission status: Accepted

Solution code:
n, k = [int(a) for a in input().split()]
ret = 0
for a in range(1, n + 1):
	cnt = 0
	tmp = a
	while(True):
		if tmp >= k:
			ret += 1/n * pow(1/2, cnt)
			break
		else:
			tmp *= 2
			cnt += 1
print(ret)

Submission status: Accepted

Solution code:
import math
N, K = [int(s) for s in input().split(' ')]
ret = [1] * N
for n in range(1, N + 1):
    p = n
    rate = 1
    if p > K - 1:
        ret[n - 1] = rate
        continue
    for i in range(100000):
        p *= 2
        rate /= 2
        if p > K - 1:
            ret[n - 1] = rate
            break

print(sum(ret) / len(ret))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ret = 0.0
p = 1.0
r = n + 1
while True:
    num = r - min(r, k)
    ret += num * p
    r   -= num
    if k == 1:
        break
    k = (k + 1) // 2
    p = p * 0.5
print(ret / n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np 

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

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

print(ans)

Submission status: Accepted

Solution code:
import math

n,k =  map(int,input().split())
lis = []
for i in range(n):
    if i+1 >= k:
        lis.append(0)
    else:
        lis.append(math.ceil(math.log2((k/(i+1)))))

#print(lis)


ans = []
for i in range(n):
    ans.append(1/n * (1/2)**lis[i])

print(sum(ans))

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
p = 0
def f(n):
  return n*2

for i in range(N+1):
  if i !=0:
    n = 0
    while(True):
      if i >= K:
        break
      i = f(i)
      n+=1
    p += (1/N)*(0.5)**n
print(p)

Submission status: Accepted

Solution code:
#abc126c

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n, k = map(int, input().split())
dice = np.arange(1, n+1)

m = np.ceil(np.log2(k) - np.log2(dice))
for i in range(n):
    if m[i] <= 0:
        m[i:] = 0
        break
p = (0.5**m)
print(sum(p)/n)

Submission status: Accepted

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

ans=0
n=20
p=[1]*n
for i in range(n-1):
    p[i+1]=p[i]*2

for i in range(1,N+1):
    temp=0
    for j in range(n):
        if i*p[j]>=K:
            temp=j
            break
    ans+=1/N/p[temp]
    
print(ans)

Submission status: Accepted

Solution code:
from math import log2,ceil

def main():
    N,K = map(int,input().split())
    ans = 0
    for i in range(1,N + 1):
        digit = ceil(log2(K) - log2(i)) if K > i else 0
        ans += (1/N)*(0.5**digit) 
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

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


for x in range(1,N+1):
    bekicount = 0
    y = x
    while y < K:
        y = y*2
        bekicount = bekicount +1
    probability = probability + (1/N)*(pow(0.5,bekicount))
    bekicount = 0
print(probability)

Submission status: Accepted

Solution code:
#INPUT
#N K

#1≤N≤10^5
#1≤K≤10^5
#入力はすべて整数

#すぬけ君は 1 〜 N の整数が等確率で出る N 面サイコロと表と裏が等確率で出るコインを持っています。
##すぬけ君は、このサイコロとコインを使って今から次のようなゲームをします。
#まず、サイコロを 1 回振り、出た目を現在の得点とする。
#得点が 1 以上 K−1 以下である限り、すぬけ君はコインを振り続ける。
#表が出たら得点は 2 倍になり、裏が出たら得点は 0 になる。
#得点が 0 になった、もしくは K 以上になった時点でゲームが終了する。
#このとき、得点が K 以上である場合すぬけ君の勝ち、
# 0 である場合すぬけ君の負けである。
# N と K が与えられるので、このゲームですぬけ君が勝つ確率を求めてください。

#OUTPUT
#すぬけ君が勝つ確率を出力せよ。
#絶対誤差または相対誤差が 10^−9以下のとき正解とみなされる。

def calcNeedCount(n, k):
    i = 0;
    val = n;
    while (val<=k-1) :
        val = val * 2
        i = i+1
    return i
        

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

res = 0.0

for n in range(1, N+1):
    needCount = calcNeedCount(n, K)
    per = (1.0/float(N)) * pow(0.5, needCount)
    res = res + per

print(res)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    s = 0
    while 2 ** s < k:
        s += 1

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,n+1):
    for j in range(k+1):
        if i*(2**j) >= k:
            ans += 1 / (n * 2**j)
            break

print(ans)

Submission status: Accepted

Solution code:
from math import ceil, log2

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys
import numpy as np

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

n, k = int_input()

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

Submission status: Accepted

Solution code:
import math
N,K = map(int, input().split())
ret = 0.0
for i in range(1,N+1):
    # print(i, math.ceil(math.log2(K/i)), ret)
    log_2_K_n = math.ceil(math.log2(K/i))
    ret += (1/N)*((0.5)**log_2_K_n if i < K else 1)
    # if ret > 1: print(ret)
    
print(ret)

Submission status: Accepted

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

for i in range(1,N+1):
    point, p = i, 1
    while point <= K-1:
        point *= 2
        p *= 0.5
    p_total += p/N
print(p_total)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
 
def main():
    N, K = list(map(int, input().split()))
 
    ans = 0
    for i in range(1, N+1):
        t = 0
        while i < K:
            i *= 2
            t += 1
 
        ans += 0.5 ** t
 
    print(ans * (1 / N))
 
 
if __name__ == '__main__':
    main()

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:
def main():
    n, k = map(int, input().split())

    res = 0
    for i in range(1,n+1):
        cnt = 0
        while i < k:
            i *= 2
            cnt += 1
        res += 1 / (n*(2**cnt))
    print(res)
    
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 / n
  cnt = i
  while cnt < k:
    cnt *= 2
    tmp /= 2
  ans += tmp
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def calculate(n,k):
    res = 0
    for i in range(n):
        indexN = i + 1

        temp = k / indexN

        if temp < 1:
            res = res + (1/n)
        else:
            t = math.log(temp,2)
            t = math.ceil(t)
            res = res + (1/n) * math.pow(0.5,t)

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

S = input()
S = S.split(" ")
n = int(S[0])
k = int(S[1])

calculate(n,k)

Submission status: Accepted

Solution code:
# coding: utf-8
from math import log2, ceil
N, K = map(int, input().split())
ans = 0
for i in range(N):
    tmp = i+1
    x = 0
    while tmp < K:
        tmp *= 2
        x += 1
    ans += 1/N * (0.5**x)
print(ans)

Submission status: Accepted

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


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
# 出た目をaとすると、log_2([N/a])回振る必要がある.
# 求めるのは(1/N)*(1/2)**log_2([N/a])

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:
N, K = map(int, input().split())
M = 0
def coin(x):
  k = 1
  while k < x:
    k *= 2
  return 1/k
for i in range(N):
  M += coin(K/(i + 1))
print(M / N)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
    temp=i
    count=0
    while temp<k:
        temp=temp*2
        #print(temp)
        count+=1
    ans+=0.5**count
print('{:.11f}'.format(ans/n))

Submission status: Accepted

Solution code:

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

prob = 0
for i in range(1, n+1):
    num = i
    tmpprob = 1 / n
    while num < k:
        num *= 2
        tmpprob /= 2
    prob += tmpprob

print(prob)

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    # i * 2^n >= K
    cnt = 0
    p = i
    for j in range(100000):
        if p >= K:
            cnt = j
            break
        p *= 2

    ans += 1/N * 1/pow(2, cnt)

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

Submission status: Accepted

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

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

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

        ans += 0.5 ** t

    print(ans * (1 / N))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

#output
#サイコロの目がi(0 <= i <= K-1)の時、iがKを超えるまで2倍していく。
#サイコロの目がi(>K)の時、ゲームは終了する。

answer = 0
if N < K :
    for i in range(1, N+1):
        temp = i
        cnt_temp = 0
        while temp < K:
            temp *= 2
            cnt_temp += 1
        answer += (1/N)*(1/2)**(cnt_temp)
else:
    for i in range(1, K):
        temp = i
        cnt_temp = 0
        while temp < K:
            temp *= 2
            cnt_temp += 1
        answer += (1/N)*(1/2)**(cnt_temp)
    for i in range(K, N+1):
        answer += (1/N)
print(answer)

Submission status: Accepted

Solution code:
# coding: utf-8

N, K = (int(x) for x in input().split())

result = 0
count = 0
for n in reversed(range(1, N + 1)):
	while(True):
		if n >= K:
			result += (1 / N) * (0.5 ** count)
			break
	
		K /= 2
		count += 1

print(result)

Submission status: Accepted

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

# more than K or K

res = []

for i in range(1, N + 1):
    # when dice is i
    if i >= K:
        res.append(1 / N)
        continue
    else:
        x = 1
        while i < K:
            x = x * 0.5
            i = i * 2
        l = (1/N) * x
        res.append(l)

print(sum(res))

Submission status: Accepted

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

ans = 0
for n in range(N):
    a = n + 1
    c = 0
    while a < K:
        a *= 2
        c += 1
    ans += (1 / N) * (0.5 ** c)
print(ans)

Submission status: Accepted

Solution code:
n, k = (int(x) for x in input().split())
ans = 0
if n >= k:
    lim = k
    ans += (n - k + 1)/n
else: lim = n + 1
for i in range(1, lim):
    num = i
    cnt = 0
    while num < k:
        num *= 2
        cnt += 1
    ans += (0.5 ** cnt) / n
print(ans)

Submission status: Accepted

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

p = 0.0
for n in range(1, N + 1):
    if K <= n:
        p += 1 / N
    else:
        t = 0
        while n < K:
            n <<= 1
            t += 1
        p += 1 / N * 0.5 ** t
print(p)

Submission status: Accepted

Solution code:
def func(n,K):
   i=0
   while n*2**i<K:
      i+=1
   return i


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

count=0
for n in range(1,N+1):
   count+=(1/N)*(1/2)**func(n,K)

print(count)

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

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

Submission status: Accepted

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

ans = 0

for i in range(1, n+1):
    m = i
    cnt = 0
    for j in range(1, 101):
        if m >= k:
            break
        else:
            m = m * 2
            cnt += 1
    ans += (1 / n) * (0.5**cnt)

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split(" "))
    result = 0
    for i in range(1, N + 1):
        point = i
        face = 0
        while point < K:
            point *= 2
            face += 1
        result += 0.5 ** face / N
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import log2, ceil


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

ans = 0
for m in range(1, N + 1):
    if m >= K:
        ans += 1 / N
    else:
        y = ceil(log2(K / m))
        prob = (0.5 ** y) / N
        ans += prob

print(ans)