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:

def count(N,K):
    a=0
    while K>N:
        N=N*2
        a=a+1
    return a




N,K=input().split()
N=int(N)
K=int(K)
a=[0]*N
for num in range(0,N):
    a[num]=num+1
ans=0
for num in range(0,N):
    ans=ans+pow(0.5,count(a[num],K))
print(ans/N)

Submission status: Accepted

Solution code:
import math


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

ans = 0

for n in range(1, N+1):
    # 2^(num_success) * n >= K なる num_success
    # 2^(num_success) >= K/n
    # num_success >= log_2(K/n)
    num_success = max(0, math.ceil(math.log2(K/n)))
    ans += (1/2) ** num_success

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
	cnt=i
	while cnt<k:
		cnt*=2
		tmp/=2
	ans+=tmp
print(ans)
# x

Submission status: Accepted

Solution code:

N,K = input().split()

N = int(N)
K = int(K)

ans = 0.0

for i in range(N):
    dice = i + 1
    point = dice

    now_prob = 1/N

    while point < K:

        point *= 2
        now_prob *= 0.5

    ans += now_prob

print (ans)

Submission status: Accepted

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


def getP(p, i):
    if i*2 < K:
        return getP(p+1, i*2)
    else:
        return p+1

ans = 0
for i in range(1, N+1):
    if i >= K:
        ans += 1 / N
    else:
        ans += 0.5 ** getP(0, i) / N

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(1, N+1):
    J = i
    t = 0
    while K > J:
        J = J * 2
        t += 1
        
    ans += (1 / N) * 0.5**t 
    
print(ans)

Submission status: Accepted

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

res = 0
for value in range(1, n + 1):
    if value >= k:
        res += (1 / n)
    else:
        # 何回コインの表を出す必要があるか
        tmp = 0
        while value * 2 ** (tmp) < k:
            tmp += 1
        res += (1 / n * (1 / 2) ** tmp)
print(res)

Submission status: Accepted

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

import math
x=0

for i in range(n):
    if i+1<k:
        e = math.ceil(math.log2(k/(i+1)))
        
        x += 1/(n*(2**e))
    else:
        x+= 1/n
print(x)

Submission status: Accepted

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

prob_list = [2 ** -(math.ceil(math.log(K / n, 2))) if n < K else 1 for n in range(1, N + 1)]
prob = sum(prob_list) / N
print(prob)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""
import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""
N, K = list(map(int, input().split()))
def main():
    p = 0.
    if K <= N:
        p += float(N-K+1)/float(N)
    if K<=N:
        r = K
    else:
        r = N+1
    for n in range(1,r):
        i = 1         
        while n*2**i<K:
            i+=1
        p += 1./float(N)*(1./2.)**(float(i)) 
            
    print(p)
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

prob_sum = 0

for i in range(N + 1)[1::]:
    current = i
    prob = 1
    while(True):
        if(K <= current):
            break
        prob = prob * 0.5
        current = current * 2
    prob_sum += prob

print(prob_sum / N)

Submission status: Accepted

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

ls = []

def multiply(ls):
    result = []
    for i in range(len(ls)):
        result.append(pow(N, -1) * ls[i])
    return result

if N < K:
    for i in range(1, N + 1):
        p = i
        cnt = 0
        while p < K:
            p *= 2
            cnt += 1
        ls.append(pow(2, -cnt))
    print(sum(multiply(ls)))
else:
    for i in range(1, K):
        p = i
        cnt = 0
        while p < K:
            p *= 2
            cnt += 1
        ls.append(pow(2, -cnt))
    print(sum(multiply(ls)) + (N - K + 1) / 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
    else:
        c=0
        s=i
        while s<=K-1:
            s=s*2
            c+=1
        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):
    l=i
    lo=0
    while l<k:
        lo+=1
        l*=2
    ans+=(1/n)*((1/2)**lo)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

n = np.arange(1,N+1)
k = np.ceil( np.log10(K/n)/np.log10(2.0) )
k[k < 0.0] = 0.0
ans = np.sum( 0.5**(k)/N )

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

Submission status: Accepted

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

lst = []
def kakuritu(val, base):
    num = 1
    while base >= val:
        val = val * 2
        num = num / 2
    num2 = (1/N) * num
    lst.append(num2)

n = 1
while n <= N:
    kakuritu(n, K-1)
    n = n + 1
ans = sum(lst)
print(ans)

Submission status: Accepted

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

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

print(p)

Submission status: Accepted

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

pro_list = []
for i in range(1,N+1):
	if i<K:
		try_number = math.ceil(math.log2(K/i))
		pro_list.append(1/ (N * 2**try_number) )
	else:
		pro_list.append(1/ N )
print(sum(pro_list))

Submission status: Accepted

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

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

    d = (2**p)
    sc = 1/(n*d)
    ttl += sc

print(ttl)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
t = []
for i in range(1, N+1):
  c = 0
  x = i
  while x<K:
    x <<= 1
    c += 1
  t.append(c)
tx = max(t)
print(1.0 * sum([1<<(tx-ti) for ti in t]) / (1<<tx) / N)

Submission status: Accepted

Solution code:
from fractions import Fraction

n, k = [int(i) for i in input().split(" ")]
p = Fraction(0, 1)

def int_log(x, y):
    r = 0
    while x < y:
        x *= 2
        r += 1
    return r

for i in range(1, n + 1):
    if i >= k:
        p += Fraction(1, n)
    else:
        p += Fraction(1, n * 2**int_log(i, k))

print('{:.10f}'.format(float(p)))

Submission status: Accepted

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

ans = 0
for i in range(1, N + 1):
    # print(i)
    need_omote = max(math.ceil(math.log2(K / i)), 0)
    ans += math.pow(0.5, need_omote)
print(ans / N)

Submission status: Accepted

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

Submission status: Accepted

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

dice_prob = 1/n
ans = 0
for i in range(1,n+1):
    if i < k:
        ans += ((0.5)**math.ceil(math.log2(k/i)))/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,min(n,k)+1):
  j = float(math.ceil(math.log(k/i)/math.log(2)))
  ans += float((1/n)*(1/2)**j) 
if k<n:
  ans += float((n-k)*1/n)
  
print(ans)

Submission status: Accepted

Solution code:
import random

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

for first_score in range(1, n + 1):
    if first_score >= k:
        pro += 1 / n
    else:
        i = 1
        while True:
            if first_score * (2 ** i) >= k:
                break
            i += 1
        pro += 1 / ((2 ** i) * n) 

print(pro)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import log2, ceil

N, K = map(int, input().split())
ans = 0
max_pow = ceil(log2(K))
for n in range(1, N + 1):
    ans += 2 ** (max_pow - max(0, ceil(log2(K / n))))
print(ans / (N * 2 ** max_pow))

Submission status: Accepted

Solution code:
import math

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

def f(n, k):
    return 0.5 ** math.ceil(math.log2(k/float(n)))
ans = 0
if K > N:
    for n in range(1, N+1):
       ans += f(n, K) * 1/N
       
else:
    for n in range(1, K):
        ans += f(n, K) * 1/N
    ans += float(N-K+1)/N
    
print(ans)

Submission status: Accepted

Solution code:
import math

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

s = 0
logK = math.log(k)
log2 = math.log(2)
for i in range(n):
    p = i + 1
    prob = 1
    while p < k:
        p *= 2
        prob *= 0.5
    s += prob
print(s / n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil, log2

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

Pr = 0.0
for dice in range(1, min(N + 1, K)):  # まだ勝ってない
    # 何回表が出たらよい?
    k = ceil(log2(K / dice))
    Pr += 1.0 / (2 ** k)

if K <= N:  # さいころだけで勝つ
    Pr += N - K + 1

Pr /= N
print(Pr)

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:
    a = math.ceil(math.log(k/i, 2)) #何回表を出せば良いか
    ans += (1/n) * (1/2)**a
  else:
    ans += (1/n)
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = 0
def rep(a,b):
    m = 0
    while a<b:
        a = a * 2
        m += 1
    return m

for i in range(1,n+1):
    if i<k:
        m = rep(i,k)
        ans += 1/(2**m)
    else:
        ans += 1
print(ans/n)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
proba = 0
for n in range(0, N+1):
    for ii in range(18):
        if n * (2 ** ii) >= K:
            proba += (1 / N) * (0.5 ** ii)
            break

print(proba)

Submission status: Accepted

Solution code:
import math
a=[int(i) for i in input().split()]
ans=0
for i in range(1,a[0]+1):
  if i>=a[1]:
    ans+=1/a[0]
  else:
    n=0
    while  i*2**n<a[1]:
      n+=1
    ans+=(1/a[0])*1/2**n
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
per = 0
for i in range(1, n+1):
    # x = math.ceil(math.sqrt(k/i)) if k > i else 0
    x = 0
    t = i
    while t < k:
        t *= 2
        x += 1
    # per += float("{:.20g}".format(1/(2**x)))
    per += 2**-x

print(per/n)

Submission status: Accepted

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

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


    while i < K:
        i *= 2
        ans *= 0.5
        count += 1
        

    sub += ans

print(sub)

Submission status: Accepted

Solution code:
def f(i, K):
  if i >= K:
    return 0
  
  upper = 50
  lower = 0

  while(upper - lower > 1):
    middle = int((upper + lower) / 2)
    if i * 2**middle >= K:
      upper = middle
    else:
      lower = middle

  return upper


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

ans = 0.0

for i in range(1, N + 1):
  x = f(i, K)
  ans += (1 / N) * (0.5)**x
  # i * 2^x >= Kとなるxが見つかったら
  # 2^x >= K / i
  # x >= log(K / i)
  # i / K >= (1 / 2)^x
  # 1 / 10 
  # ans += (1/2)^x * (1 / N)をするのです

print(ans)

Submission status: Accepted

Solution code:
def solve(n, k):
    res = 0
    for x in range(1, n+1):
        y = x
        while y < k:
            y *= 2
        res += 1.0 * x / y
    return res / n

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    if i+1 < k:
        c = 0
        t = i+1
        while t < k:
            t *= 2
            c +=1
        
        ans += (1/n)*(1/2)**c
    
    else:
        ans += (1/n)*(n-i)
        break

print(ans)

Submission status: Accepted

Solution code:
def pow2(n):
	res = 1
	for i in range(0, n):
		res *= 2
	return res

counter = [0]
N, K = map(int, raw_input().split())
for i in range(1, N+1):
	m = i
	cnt = 0
	while m < K:
		m *= 2
		cnt += 1
	counter.append(cnt)
sum = 0
for i in range(1, N+1):
	sum += pow2(counter[1]-counter[i])
dv = N*pow2(counter[1])
print float(sum)/float(dv)

Submission status: Accepted

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

pro = []
q = 1

for i in range(N):
    for j in range(K):
        q = 2**j
        if (i+1)*q >= K:
            break
    pro.append((1/N) * (1/q))
    q = 1

ans = 0
for i in range(N):
    ans = ans + pro[i]

print(ans)

Submission status: Accepted

Solution code:
import math

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

p = 0.0

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

p /= n
print(p)

Submission status: Accepted

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

p = [0] * (n+1)

for i in range(1,n+1):
    r = k / i
    t = 0
    while 2 ** t < r:
        t += 1
    #print(t)
    p[i] = 0.5 ** t

#print(p)

print(sum(p)/n)

Submission status: Accepted

Solution code:
import math

def main():
    n,k=list(map(int,input().split(' ')))
    ans = 0
    for i in range(1,min(n+1,k)):
        ans +=(1/2)**(-(math.log2(k/i)//-1))
    if n >= k:
        ans += (n-k+1)
    print(ans/n)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math

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

prab = 0

for i in range(1, N+1):
    lo = math.log2(K/i)
    if lo < 0:
        lo = 0
    elif lo != int(lo):
        lo += 1

    prab += 1/pow(2., int(lo))

print(prab/N)

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 tmp < k:
        tmp *= 2
        cnt += 1
    ans += (1/n) * pow((1/2), cnt)
print(ans)

Submission status: Accepted

Solution code:
import sys
from numpy.random import *

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

kakuritu=0
for i in range(N):
    score = i+1
    ka=1/N
    while (score < K):
        ka/=2
        score*=2    
    kakuritu +=ka

print(kakuritu)

Submission status: Accepted

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

result = 0

for i in range(1, N + 1):
    c = 0
    while i < K:
        c += 1
        i *= 2
    result += 1 / (2 ** c) / N

print(result)

Submission status: Accepted

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

p = 0

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

print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
def wari(x):
  an=x
  b=0
  while an<K:
    an=an*2
    b=b+1
  return b

for i in range(N):
  a=i+1
  b=wari(a)
  ans=ans+(0.5)**b
  
print(ans/N)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
s = b
p = 0.0
for i in range(1,a+1):
	tmp = 1.0/a
	now = i
	while now < b:
		now = now*2
		tmp = tmp/2
	p = p+tmp
print(p)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
list=input().split(" ")
num1=int(list[0])
num2=int(list[1])


probability_i=[]

for i in range(1,num1+1):
    count=0
    point=i
    while point<num2:
        point+=point
        count+=1
    prob=1/num1*(1/2)**count
    probability_i.append(prob)
ans=0
for j in probability_i:
    ans+=j
if ans>1:
    ans=1
print(ans)

Submission status: Accepted

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

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

print(p / N)

Submission status: Accepted

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

#list =[0 for i in range(N)]
p = 0
for i in range(N):
    i = i+1
    l = i
    b = 0
    if K<=i:
        p += 1/N
    else:
        while 1:
            if K <= i:
                p += (1/N)*(1/(2**b))
                #p += 1/2**b
                break
            else:
                b += 1
                i = i*2
print('{:.9f}'.format(p))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().split())
ans = 0
for i in range(1, n + 1):
	cur = i 
	twos = 0
	while cur < k:
		cur *= 2
		twos += 1
	ans += pow(0.5, twos)
print ans*(1.0/n)

Submission status: Accepted

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

    res = 0

    for i in range(1, N + 1):
        tmp_prob = 1 / N
        tmp_val = i
        while tmp_val < K:
            tmp_val *= 2
            tmp_prob /= 2

        res += tmp_prob

    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

for i in range(n):
    if i + 1 >= k:
        e = 0
    else:
        e = int(math.log2((k - 1) / (i + 1))) + 1
    ans += 0.5 ** e

print(ans / n)

Submission status: Accepted

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

Submission status: Accepted

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

n = 0
m = 1
res = []
while m<=N :
	n = 0
	while True :
		if m*pow(2,n) >= K :
			res.append(n)
			m+=1
			break
		n+=1
pr = 0
for n in res :
	pr += (1/N)*pow(1/2,n)
print(pr)

Submission status: Accepted

Solution code:
n = [int(s) for s in input().split(" ")]
k = n[1]
ans = 0

for l in range(n[0]):
    m = 0
    while (l+1)*2**m < k:
        m += 1
    ans += (1 / 2**m) * (1/ n[0])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

p = 0

for i in range(1,N+1):
	num = 0
	count = 0
	if i < K:
		num = i
		while num < K:
			count = count + 1
			num = num * 2
	p = p + ((1 / N ) * pow(0.5,count))
print(p)

Submission status: Accepted

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

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

print(p)

Submission status: Accepted

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


if __name__ == '__main__':
    n, k = list(map(int, input().split()))

    ans = []
    for i in range(1, n+1):
        tmp = i
        j = 0
        while tmp < k:
            j += 1
            tmp *= 2
        ans.append((1 / n) * ((1 / 2) ** j))

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

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, k = readmi()
ans = 0
l = int(math.ceil(math.log2(k)))
for i in range(1, n + 1):
    s = 1 / (n)
    p = i
    t = 1
    for j in range(l):
        if p >= k:
            break
        p = p * 2
        t /= 2
    ans += (s * t)
print(ans)

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, k = readmi()
ans = 0
for i in range(1, n + 1):
    s = 1 / (n)
    p = i
    t = 1
    while (k > p):
        p = p * 2
        t /= 2
    ans += (s * t)
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:
        p = 1 / n
        while (i < k):
            i *= 2
            p *= (0.5)
        ans += p
print(ans)

Submission status: Accepted

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

p = 0

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

print(p)

Submission status: Accepted

Solution code:
import math

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

win_prob = 0
for k in range(1, N+1):
  m = max(math.ceil(math.log2(K / k)), 0)
  win_prob += 1/N * 0.5**m

print(win_prob)

Submission status: Accepted

Solution code:
def prob(x, N, K):
    a = 1
    while x * (2 ** a) < K:
        a += 1
    return (1 / N) * ((1 / 2) ** a)

N, K = list(map(int, input().strip().split(' ')))

ans = sum(prob(i+1, N, K) for i in range(N)) if N < K else (N - K + 1)/N + sum(prob(i+1, N, K) for i in range(K-1))
print(ans)

Submission status: Accepted

Solution code:
import sys

n=input()
num = n.split()
a=int(num[0])
b=int(num[1])

def checkMultiNum(base, dst):
	num=0
	while True:
		if base >= dst:
			break;
		num+=1
		base = base * 2
		if base >= dst:
			break;
	return num

prob=1/a
res=0
if a >= b:
	res=prob*(a-(b-1))
for v in range(a):
	if v+1 >= b:
		break;
	num = checkMultiNum(v+1, b)
	tmp = prob * 0.5**num
	res += tmp

print(res)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import math
l = list(map(int,input().split()))
N = l[0]
K = l[1]

ans = 0
 
for i in range(N):
    C = i + 1
    if C < K:
        n = math.log(K / C, 2)
        n = math.ceil(n)
        p = (1 / N) * ((1 / 2) ** n)
        
    else:
        p = 1 / N
    #print("C = " + str(C))
    #print(n)
    
    ans += p

print(ans)

Submission status: Accepted

Solution code:
import sys

n=input()
num = n.split()
a=int(num[0])
b=int(num[1])

def checkMultiNum(base, dst):
	num=0
	while True:
		if base >= dst:
			break;
		num+=1
		base = base * 2
		if base >= dst:
			break;
	return num

prob=1/a
res=0
for v in range(a):
	num = checkMultiNum(v+1, b)
	tmp = prob * 0.5**num
	res += tmp

print(res)

Submission status: Accepted

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

Prob = 0

for i in range(N):
  score = i+1
  if score >= K:
    Prob += 1/N
  else:
    mk = 1
    while  score*2**mk < K:
      mk += 1
    Prob += 1/N*0.5**mk

print(Prob)

Submission status: Accepted

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

for i in range(1,n+1):
    count = 0
    temp = i
    while temp < k:
        temp *= 2
        count += 1
    seq.append(count)

for i in range(n):
    result += 1/n * (0.5)**seq[i]
    
    
print(result)

Submission status: Accepted

Solution code:
'''
すぬけ君は 1 〜 N の整数が等確率で出る N 面サイコロと表と裏が等確率で出るコインを持っています。
すぬけ君は、このサイコロとコインを使って今から次のようなゲームをします。
まず、サイコロを 1 回振り、出た目を現在の得点とする。
得点が 1 以上 K−1 以下である限り、すぬけ君はコインを振り続ける。
表が出たら得点は 2 倍になり、裏が出たら得点は 0 になる。
得点が 0 になった、もしくは K 以上になった時点でゲームが終了する。

このとき、得点が K 以上である場合すぬけ君の勝ち、 0 である場合すぬけ君の負けである。

N と K が与えられるので、このゲームですぬけ君が勝つ確率を求めてください。

'''
import math

def main():
	'''
	メイン関数
	'''
	# N面サイコロ, 判定K
	N, K = map(int, input().split())

	# while
	sum  = 0
	for i in range(1,N+1):
		
		x = 0
		while(i*2**x < K) :
			x = x + 1

		sum = sum + (1/N ) * (1/2) ** x  

	print(sum)



if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import math

# NとKの入力、Nはサイコロの面の数,Kは得点
strings = input().split()

n = int(strings[0])
k = int(strings[1])
prob = 0
'''
x = int(math.log(k / n, 2)) + 1
print(x)
prob = (1 / 3) * pow(1 / 2, x)
'''
# 1~Nまでのサイコロによるそれぞれの確率を算出
for num in range(1, n+1):
    if num < k:
        x = math.ceil(math.log2(k / num))
        prob += pow(1 / 2, x)
    else:
        prob += 1
print(prob / n)

Submission status: Accepted

Solution code:
import math
N,K=[int(i) for i in input().split()]
res=0
for i in range(1,N+1):
	if i<K:
		po=math.ceil(math.log2(K/i))
		j=math.pow(0.5,po)
	else:
		j=1
	res+=j
print(res/N)

Submission status: Accepted

Solution code:
from decimal import *

dp = [0] * 100000

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

n_count = n
p_count = 0

while n_count:
    var = n_count * (2 ** p_count)
    if k - 1 < var:
        dp[p_count] += 1
    else:
        while var <= k - 1:
            var *= 2
            p_count += 1
        dp[p_count] += 1
    n_count -= 1

ans = Decimal(0)
for i, d in enumerate(dp):
    if d != 0:
        ans += Decimal(1/n) * (Decimal(1/2) ** i) * d

print(ans)