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:
N, K = map(int, input().split(" "))
count = []
ans = 0
for i in range(N):
    score = i + 1
    n = 0 
    while  True:
        if score >= K:
            break
        else:
            score *= 2
            n += 1
    count.append(n)

for m in count:
    ans += 2 ** (-m)

print(ans / N)

Submission status: Accepted

Solution code:
# from fractions import Fraction
from decimal import Decimal
li = input().split()
n = int(li[0])
k = int(li[1])

# n面サイコロ kは得点

# 1/nの確率で1~nが出る
# 勝つためにx回表を出し続ければ良い
# 目 * 2^x >= kとなればよい

answer = 0
for i in range(n):
    dicenum = i + 1
    winline = dicenum
    x = 0
    while winline < k:
        x += 1
        winline = dicenum * (2**x)
    if dicenum == 1:
        first_x = x
        bunbo = n * 2**x #initialize
        bunsi = 1 #initialize
    elif x == 0:
        bunsi += 2**first_x
    else:
        bunsi += 2**(first_x - x)

answer = Decimal(str(bunsi)) / Decimal(str(bunbo))
print("{:.12f}".format(answer))

Submission status: Accepted

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

dices = [i for i in range(1, n + 1)]
ans = 0
m = 0
while len(dices) > 0:
	ans += (0.5 ** m) * (len([x for x in dices if x >= k]) / n)
	dices = [2 * x for x in dices if x < k]
	m += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    result=[]
    n,k=list(map(float, input().split()))
    for i in range(1,int(n)+1):
        value=float(i)
        count=1
        while value<k:
            value=value*2
            count/=2
        result.append(count)
    print(sum(result)/n)
main()

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
from math import ceil, log2
m_list = [(1/2)**ceil(log2(K/(n+1))) if n+1<K else 1 for n in range(N)]
#print(m_list) #各nに対し勝つのに必要な表の数
print(sum(m_list)/N)

Submission status: Accepted

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

array = []
for i in range(N):
    n = i+1
    nankai = 0
    while n < K:
        n = n * 2
        nankai += 1
    array.append(nankai)

kakus = 0
for k in array:
    kaku = 1 / N
    for q in range(k):
        kaku = kaku / 2
    kakus += kaku

print(kakus)

Submission status: Accepted

Solution code:
import math

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

if N>=K:
	ans = (N-K+1)/N
	for k in range(1, K):
		n = math.ceil(math.log2(K/k))
		ans += (1/N)*(1/2**n)
else:
	ans = 0
	for k in range(1, N+1):
		n = math.ceil(math.log2(K/k))
		ans += (1/N)*(1/2**n)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
log = np.log
N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
  ans += 2 ** -np.ceil(log(K/i)/log(2)) if i < K else 1
ans /= N
print(ans)

Submission status: Accepted

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

N, K = map(int, input().split())
l = [0] * N

for i in range(1, N + 1):
    count = 0
    c = i
    while c < K:
        c *= 2
        count += 1
        
    l[i - 1] = (1 / N * (0.5 ** count))
    
print(sum(l))

Submission status: Accepted

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

x = 0
ans = 0
for i in range(1,n+1):
    if i>=k:
        ans += 1/n
    else:
        x = math.ceil(math.log2(k/i))
        if x>0:
            ans += (1/n)*(1/2)**x
print(ans)

Submission status: Accepted

Solution code:
miu = input().split()

qurare = []

for x in range(int(miu[0])):
	if (x+1) >= int(miu[1]):
		qurare.append(1/int(miu[0]))
		continue

	delphine = 1
	while True:
		if (x+1) * 2 ** delphine >= int(miu[1]):
			qurare.append(1/int(miu[0]) * pow(0.5, delphine))
			break
		delphine += 1

print(sum(qurare))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, N+1):
	if i >= K:
		cnt += 1
	else:
		for x in range(1, 100000):
			i = i * 2
			if i >= K:
				cnt += 1 / (2 ** x)
				break

ans = cnt / N
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b = map(int, input().split())
prob = list()
for i in range(a):
    n = i+1
    if n >= b:
        prob.append(1)
        continue
    for j in range(b):
        c = 2 ** j
        if (n * c >= b):
            prob.append(c)
            break

probability = 0
for d in prob:
    if (d == 1):
        probability += 1 / a
    else:
        probability += 1 / (a * d)
print(probability, end='')

Submission status: Accepted

Solution code:
s=input().split(" ")
xi=int(s[0])
k=int(s[1])

bi=[float(2**i) for i in range(18)]
j=0
_sum=float(0)

for i in range(1,xi+1):
  j=0
  while k>float(i)*float(bi[j]):
    j+=1
  _sum+=(float(1.0)/float(bi[j]))

print((float(1.0)/float(xi))*float(_sum))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
s = 0
for i in range(1000):
    if 2**i <= k < 2**(i+1):
        s = i+1
        break
t = 0
for i in range(n):
    if s == 0 and k<=n:
        t+=1
        
    elif k<=(i+1) *2**s and k> (i+1) *2**(s-1):
        t+=1/(2**s)
    else:
        s-=1
        t+=1/(2**s)
print(t/n)

Submission status: Accepted

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

def n_over(a, k):
  n = 0
  while(a < k):
    a *= 2
    n += 1
  return n

n = 1
while(n <= N):
  kaisu = n_over(n, K)
  percent = (1/N) * (0.5**(kaisu))
  p += float(percent)
  n += 1

print(p)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
dice = 1 / n
ans = []
for i in range(1,n+1):
    if i >= k:
        ans.append(dice)
    else:
        k1 = i
        count = 0
        while k > k1:
            k1 = k1 * 2
            count += 1
        ans.append(dice * (0.5 ** count))
print(sum(ans))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------
# ### DEBUG ###
#
# from IPython.core.debugger import Pdb; Pdb().set_trace()
import sys
from math import log2, ceil
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,K = map(int, lines.pop(0).split(' '))
    res = 0
    for i in range(1,N+1):
        if i > K:
            res += 1/N
        else:
            t = K / i
            c = ceil(log2(t))
            res += 1/N *  (1/2) ** c
    print(res)


#
# main
#

# 1. use list instead of stdin
# 
# contents = '''\
# 3 10
# \
# '''
# lines = contents.split('\n')
# 
# 2. use stdin

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Accepted

Solution code:
a = input().split()
n = int(a[0])
k = int(a[1])

b = k // 2
d = 0

for i in range(n):
  c = i + 1
  if c >= k:
    d += 1 / n
    continue
  for j in range(k):
    c *= 2
    if c >= k:
      d += (0.5 ** (j+1)) / n
      break

print(d)

Submission status: Accepted

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

import math
ans = 0
for i in range(N):
    a = math.ceil((math.log(K/(i+1)))/math.log(2))
    if a<0:
        a=0
    ans += (1/N)*((1/2)**a)

print(ans)

Submission status: Accepted

Solution code:
def f(x, y):
    i = 0
    while x < y: i += 1; x *= 2
    return i

n, k = map(int, input().split())
p = (max(0, n - k + 1) +
     sum(1/(2**f(i, k)) for i in range(1, min(k, n + 1)))) / n
print(p)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
from math import ceil, log2
m_list = [ceil(log2(K/(n+1))) if n+1<K else 0 for n in range(N)]
#print(m_list) #各nに対し勝つのに必要な表の数

#
# m_list = []
# for n in range(N):
#     if n+1 >=

def calc_prob(x):
    return (1/2)**x

prob_list = list(map(calc_prob,m_list))

# Kより大きいインデックスのところは1に書き換え
#print(prob_list)
print(sum(prob_list)/N)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
n=1
p=0.0
while n<=N:
  n2=n
  p2=1.0
  while n2<K:
    n2*=2
    p2/=2
  p+=p2/N
  n+=1
print(p)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

kaku = [1/n] * n
for i in range(n):
    point = i + 1
    while point < k:
        kaku[i] /= 2
        point *= 2
kakuritu = 0
for j in range(n):
    kakuritu += kaku[j]

print(kakuritu)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

ct = 0
ans = 0.0

for i in range(1,n+1):
    pt=i;
    while pt <= k-1:
        pt=pt*2;
        ct+=1
    ans+= 1.0/n * pow(0.5, ct)
    ct=0
    
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N,K = map(int, input().split())
ans = 0
logK = np.log2(K)
if N < K:
    for i in range(N):
        sisu = int(logK - np.log2(i + 1))
        if np.log2(K/(i+1)) != int(np.log2(K/(i+1))):
            sisu += 1
        ans +=1 / (2 ** sisu)
    print(ans/ N)
else:
    for i in range(K - 1):
        sisu = int(logK - np.log2(i + 1))
        if np.log2(K/(i+1)) != int(np.log2(K/(i+1))):
            sisu += 1
        ans +=1 / (2 ** sisu)   
    ans += N - K + 1
    ans = ans / N
    print(ans)

Submission status: Accepted

Solution code:
import math
inputa = input().split()
inputa[0] = int(inputa[0])
inputa[1] = int(inputa[1])
tempa = []
tempb = float(inputa[1])
tempc = []
res = float(0)
if tempb == 1:
	print(1)
	exit()
while tempb >= 0.5:
	#print(tempb)
	if tempb <= inputa[0]:
		tempa.append(math.floor(inputa[0] - tempb + 1))
	else:
		tempa.append(0)
	tempb /= 2

i = 1
tempc.append(tempa[0])
#print(tempa)
while i < len(tempa):
	tempc.append(tempa[i] - tempa[i - 1])
	i += 1
#print(tempc)
for i, num in enumerate(tempc):
	#print(num / inputa[0] / (2 ** i))
	res += num / inputa[0] / (2 ** i)

print(res)

Submission status: Accepted

Solution code:
def pows(n, K):
    count = 0
    while True:
        if n >= K:
            return count
        n = n * 2
        count += 1


def main():
    N, K = list(map(int, input().split()))
    # re = max(N - K, 0) / N
    re = 0
    # print(re)
    for i in range(1, N + 1):
        if i >= K :
            re = re + 1 / N
            continue
        p = pows(i, K)
        # print(p)
        re = re +  pow(0.5, p) / N
    print(re)
    # print(re / N)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
n,k = map(int, input().split())
ans = 0
if n>=k:
    ans += 1-k/n
iterate = k if n>k else n
for i in range(1,iterate+1):
    temp = math.log2(k/i)
    temp = int(temp) if temp%1==0 else int(temp)+1
    ans += (1/n)*math.pow(0.5,temp)
print(format(ans, '.20f'))

Submission status: Accepted

Solution code:
N, K = map(int, input().rstrip().split(' '))
result = 0.0

def get_n(num, K):
    now_score = num
    for i in range(20):
        if now_score >= K:
            return i
        now_score *= 2

for i in range(1, N+1):
    n = get_n(i, K)
    i_score = (1/N) * ((1/2)**n)
    result += i_score

print(result)

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:
    ans += 1 / n
  else:
    ans += np.power(1 / 2, np.ceil(np.log2(k / i))) / n
    
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import types
import copy
import math

# Input
l = list(map(int, input().split()))
N = l[0]
K = l[1]
win_rate = 0

def calcNeedCount(d, k):
    point = d
    count = 0
    while point < k:
        point = point * 2
        count += 1

    return count


n = copy.deepcopy(N)
while n > 0:
    dice = n

    # Calc need count
    need = calcNeedCount(dice, K)
    #print("need", need)

    win_rate += (1/N) * math.pow(1/2, need)

    n += -1

# Print
print(win_rate)

Submission status: Accepted

Solution code:
import math

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

for i in range(1, N + 1):
    if i < K:
        target = K / i
        exponent = math.log(target, 2)
        prob = (1 / N) * (1 / 2)**math.ceil(exponent)
        prob_sum += prob
    else:
        prob = 1 / N
        prob_sum += prob
print(prob_sum)

Submission status: Accepted

Solution code:
import math
a=[]#入力画面の二文字を別々の文字に格納
a=input().split(" ")
N=int(a[0])
K=int(a[1])

q=0
if K<=N:
    for i in range(1,K):
        p=(0.5)**(math.ceil(math.log2(K/i)))
        q=p+q
    x=q/N
    y=(N-K+1)/N
    print(x+y)
elif N<K:
    for i in range(1,N+1):
        p=(0.5)**(math.ceil(math.log2(K/i)))
        q=p+q
    print(q/N)

Submission status: Accepted

Solution code:
import collections
import decimal

N, K = map(int,input().split())
coin = [0] * (K+1)
ans = 0

for i in range(K-1,0,-1):
    coin[i] += 1
    for j in range(1,20):
        if i % (2**j) == 0:
            coin[i//(2**j)] += 1

if N >= K:
    ans += N-K+1

A = collections.Counter(coin[1:min(N+1,K)]).most_common()

for tmp in A:
    ans += (0.5)**tmp[0] * tmp[1]

print(decimal.Decimal(ans/N))

Submission status: Accepted

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

C=0
for i in range(1,N+1):
    c=i
    for j in range (10**5):
        if c >= K:
            break
        else:
            c *= 2
    C += (1/N)*(0.5)**j
print(C)

Submission status: Accepted

Solution code:
import math

def main():
    temp = input().split()
    N = int(temp[0]); K = int(temp[1])
    need_omote = []
    for n in range(1, N+1):
        temp = float(K/n)
        count = 0
        while(1):
            if(temp <= 1):
                break;
            else:
                temp = temp/2
                count += 1
        need_omote.append(count)
    kakeru = 0
    for n in range(N):
        if(need_omote[n] > -35):
            kakeru += 1/(2**need_omote[n])
    ans = float(kakeru/N)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


import math


# In[68]:


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


# In[73]:


ans = 0
if K > 1:
    for i in range(1,N+1):
        ans += (1/2)**(max(math.floor(math.log((K-1)/i, 2)) + 1, 0))/N
else:
    ans = 1


# In[74]:


print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=[]
en=0
for s in range(1,n+1):
 m=0
 en=0
 while en==0:
  if (2**m)*s<k:
    m+=1
  else:
    a.append(1/2**m)
    en+=1

print(sum(a)/n)

Submission status: Accepted

Solution code:
import math

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

p = 0.0
for i in range(1, N+1):
    if i < K:
        a = math.log2(float(K)/float(i))
        if a.is_integer():
            a = int(a)
        else:
            a = int(a) + 1
        p1 = (1/float(N))*pow(0.5, a)
        p = p + p1
    elif i >= K:
        p = p + (1/float(N))

print(p)

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
def times(i):
    a = 0
    for x in range(0, k):
        if i*(2**x)>=k:
            a = round((1/n)*(0.50**x),15)
            break
    return a
       
ans = 0
for i in range(1, n+1):
        ans += times(i)
print(ans)

Submission status: Accepted

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

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

    ans += (0.5 ** cnt) / n

print(ans)

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
a = 0
ans = 0.0
for i in range(1,n+1):
    if i*2 < k:
        a = math.log2(k/i)  # 何回勝てばいいか
        c = math.ceil(a)
        b = float(1/n)
        d = (1.0/2.0) ** c
        ans += b*d

    elif i < k < i*2:
        ans += float(1/n)*0.5

    else:
        b = float(1/n)
        ans += b*1

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
#1~k-1で続行
p=1/n
if n>=k:
    l=k
    win=(n-k+1)/n
else:
    l=n+1
    win=0
lst=[]
for i in range(1,l):
    x=i
    count=0
    while x < k:
        x*=2
        count += 1
    lst.append(count)
result=0
for i in lst:
    result+=(1/2)**i
print(result*p+win)

Submission status: Accepted

Solution code:
import math

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

ret = (N - K + 1) if N > K else 0
counter = N + 1 if N < K else K
C = 1 / N
tmp = 0
e = math.ceil(math.log2(K/1))
pro = 1
for i in range(e):
    pro *= 2
tmp = 1/pro
for  i in range(2,counter):
    e_next = math.ceil(math.log2(K/i))
    if e_next < e:
        e = e_next
        pro /= 2
    tmp += 1/pro
print((ret + tmp)/N)

Submission status: Accepted

Solution code:
from math import log2, ceil

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

ans = 0.

for k in range(1, N+1):
    if k >= K:
        ans += 1. / float(N)
        continue
    tmp1 = float(ceil(log2(K / k)))
    tmp = 0.5**tmp1
    ans += tmp / float(N)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

jou_list = [0 for _ in range(N)]
n_list = [i+1 for i in range(N)]

for i in range(N):
    m = 0
    ii = n_list[i]
    while ii < K:
        m += 1
        ii *= 2
    jou_list[i] = m

ans = 0
for i in range(N):
    ans += 1/(2**jou_list[i])

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

print(ans)

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
result = 0
for first_dice in range(1, n + 1):
    front_count = max(math.ceil(math.log(k / first_dice, 2)), 0)
    result += (1 / n) * (1 / 2) ** front_count

print(float(result))

Submission status: Accepted

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

import math
val = K
curr_max = N
result = 0

pow_count = 0
while curr_max >= 1:
    if curr_max >= val:
        ceil = curr_max-math.ceil(val)+1
        result += ceil/N * ((0.5) ** pow_count)
        curr_max = math.ceil(val-1)
    val *= 0.5
    pow_count += 1

print result

Submission status: Accepted

Solution code:
import math
N, K = input().split(" ")
N, K = int(N), int(K)
P = 0
if (N < K):
  for n in range(1,N+1):
    P += 1/(N*pow(2,math.ceil(math.log2(K)-math.log2(n))))
else:
  for n in range(1, K+1):
    P += 1/(N*pow(2,math.ceil(math.log2(K)-math.log2(n))))
  P += (N-K)/N
print(P)

Submission status: Accepted

Solution code:
from decimal import Decimal, ROUND_DOWN
N,K = map(int, input().split())
l = []
for i in range(N):
    if i >= K:
        break
    a = 0
    for j in range(K):
        if j == 0:
            a = i+1
        else:
            a = a * 2
        if a >= K:
            break
    kakuritsu = 1/N*(0.5**j)
    l.append(kakuritsu)
s = sum(l)
if N > K:
    ans = s + (N-K)/N
else:
    ans = s
print("{0:.10f}".format(Decimal(ans)))

Submission status: Accepted

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

total = []
s_c = 0
for i in range(n):
    s = i+1
    num = 1
    if s <= (k/2) :
        while s*2 < k:
            num += 1
            s = s*2
    elif s >= k:
        break
    s_c += 1
    total.append(num)
o = 0
for j in range(s_c):
    o += (1/n) * (0.5 ** total[j])
if s_c != n:
    o += (n-s_c)/n
print(o)

Submission status: Accepted

Solution code:
import math

e = 10**(-7)
n,k = map(int, input().split())
ans = 0
for i in range(1,n+1):
    if i >= k:
        ans += 1
    else:
        ans += (1/2)**(int(math.log2((k-e)/i))+1)
    
print(ans / n)

Submission status: Accepted

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

Submission status: Accepted

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

answer = 0
for c in range(1, n + 1):
    coin_num = 0
    while c < k:
        c *= 2
        coin_num += 1
    prob = (1 / n) * (1 / 2) ** coin_num
    answer += prob

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

poss = 0
posssum = []
for i in range(1,N+1):
	point = i
	cou = 0
	while point <= K-1:
		point = 2*point
		cou=cou+1
#	print('cou=',cou)
	poss = 1.0/float(N) * 0.5 **(cou)
	posssum.append(poss)
#	print(poss)
print(sum(posssum))

Submission status: Accepted

Solution code:
import sys
import math

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

res = 0.0

for i in range(1,n+1):
  if k <= i :
    res = res + 1
    continue
  for j in range(1,math.floor(math.log2(k))+2):
    if (i * (2 ** j)) >= k :
      res += 0.5 ** j
      break
res = res / n
print(res)

Submission status: Accepted

Solution code:
def gcd(a, b):
    while b:
	    a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

n, k = list(map(int, input().split()))
a_list =[]
for i in range(n):
    cnt = 0
    tmp = i+1
    while tmp < k:
        tmp *= 2
        cnt += 1
    if i < k:
        a = n*2**cnt
    else:
        a = n
    a_list.append(a)
_lcm = a_list[0]
for i in range(1, n):
    _lcm = lcm(_lcm, a_list[i])
tmp = 0
for a in a_list:
    tmp += _lcm / a
print(tmp/_lcm)

Submission status: Accepted

Solution code:
import math

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

ans = 0

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
dice = [int(i+1) for i in range(n)]
point = 0
prob = 0
ans = 0
for i in range(n):
    point += dice[i]
    prob += 1/n

    while point <= k-1:
        point *= 2
        prob *= 0.5

    ans += prob
    point = 0
    prob = 0

print(ans)

Submission status: Accepted

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

ans = 0

for n in range(1,N+1,1):
    score = n
    temp = 1
    while True:
        if K <= score:
            ans += temp/N
            break
        score *= 2
        temp /= 2

print(ans)

Submission status: Accepted

Solution code:
import sys
import os

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


count=[0]*N

KK=K
i=0
while  KK >= 1:
    i=i+1
    for j in range(int(KK)):
        if j<N and (j+1)!=KK:
            count[j]=count[j]+1
        #print(j)
    KK=KK/2

sum=0
for l in range(N):
    sum=sum + (1/N)*(1/2)**(count[l])


print(sum)

Submission status: Accepted

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

import math


p = 0

for i in range(n+1):
    if i>0:
        if i>=k:
            p += 1
        else:
            p += 2**(int(30+math.log2(i/k))-30)
print(p/n)

Submission status: Accepted

Solution code:
import math
Input = input().split()
N = float(Input[0])
K = float(Input[1])

result = float(0)
p = float(1/N)
i = 0

if N >= K:
    result = result + (N - K + 1) * p
    N = K - 1

while K > 1:
    K = K / 2
    x = float(math.ceil(K))
    i += 1
    if N >= x:
        q = 0.5**i
        result = result + (N - x + 1) * q * p
        N = x - 1

print(result)

Submission status: Accepted

Solution code:
n,k=map(float,input().split())
ans=0
l=[[k,0]]
k1=k
ll=0
while k1>1:
    k1/=2
    ll+=1
    l+=[[k1,ll]]
l.reverse()
ll+=1
l+=[[100001,ll]]
for i in range(ll):
    if l[i+1][0]<n:
        ans+=(int(l[i+1][0]-0.000001)-int(l[i][0]-0.000001))/n/2**l[i][1]
    else:
        ans+=(n-int(l[i][0]-0.000001))/n/2**l[i][1]
        break
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import math

N,K=map(int,input().split())
prob = [0]*N


for ii in range(1,N+1):
    index = math.ceil(np.log2(K/ii))
    if index <= 0:
        prob[ii-1] = 1/N
    else:
        prob[ii-1] = 1/N * (1/2)**index

print(sum(prob))

Submission status: Accepted

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

Submission status: Accepted

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


ans = 0

def calc(i):
    bb = 1
    while i * (2 ** bb) < K:
        bb +=1    
    return bb

for i in range(1, N + 1):
    if i >= K:
        ans += 1 / N
    else:
        y = calc(i)
        ans += 1 / N * (1/2) ** y

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
input = sys.stdin.readline

# N = int(input())
# L = [int(x) for x in input().split()]
N, K = map(int, input().split())
# S = input()

max_pow = math.ceil(math.log2(K) + 0.9)

one_half = [0] * (max_pow + 1)
one_half[0] = 1
for i in range(1, max_pow + 1) :
    one_half[i] = one_half[i - 1] * 0.5

ans = 0
for i in range(1, N + 1) :
    pow_num = math.ceil(math.log2(K / i))
    
    if pow_num <= 0 :
        ans += 1
    else :
        ans += one_half[pow_num]

print(ans / N)

Submission status: Accepted

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

ans = 0
for i in range(1, n + 1):
    if i < k:
        quotient = k / i
        base = math.ceil(math.log2(k / i))
        ans = ans + (1 / (2 ** base) / n)
    else:
        ans = ans + 1 / n

print(ans)

Submission status: Accepted

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

rate = 0

temp = 1
cnt = 0

while True:
  if temp >= k:
    break
  else:
    temp *= 2
    cnt += 1

for i in range(1, n + 1):
  if i * (2 **cnt) >= k > i * (2 ** (cnt - 1)):
    rate += 1 / n * 0.5 ** cnt
  else:
    cnt = max(0, cnt - 1)
    rate += 1 / n * 0.5 ** (cnt)

print(rate)

Submission status: Accepted

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

if __name__=="__main__":
    sol()

Submission status: Accepted

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

    if N - K >= 0:
        sum = sum + N - K + 1.0

        for i in range(1, K):
            tmp = i
            count = 0
            while tmp < K:
                tmp = tmp * 2
                count += 1
            sum = sum + 0.5**count
    else:
        for i in range(1, N + 1):
            tmp = i
            count = 0
            while tmp < K:
                tmp = tmp * 2
                count += 1
            sum = sum + 0.5**count

    print(round(sum/N, 10))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# スペース区切りの整数の入力
N, K = map(float, input().split())
ans = 0.0

import math #mathだとatcoderでは怒られる

for i in range(int(N)):
  #print(i+1)
  
  if i+1 <= K:
    #print("coin")
    coin_flip_number = (math.ceil(math.log(K/(i+1), 2)))
    ans = ans + (1/N)*(1/(2**coin_flip_number))
    #print((1/N)*(1/(2**coin_flip_number)))
  else:
    #print("No coin")
    ans = ans + (1/N)
    #print(1/N)
    
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

N, K = input().split()

N = float(N)
K = float(K)

c = 0.0

if N > K:
    A = K/N
else:
    A = 1.0

for i in range(1,int(N)+1):
    if i > K:
        c += 1/N
    else:
        n = np.ceil(np.log2(K/i))
        c += 1/N*(1.0/2.0)**n

print(c)

Submission status: Accepted

Solution code:
import math
from fractions import Fraction

NK = [int(i) for i in input().split()]
answer = [0.0] * NK[0]

for i in range(NK[0]):
    f = float(math.log2(NK[1]) - math.log2(i+1))
    if(f.is_integer()):
        value = int(math.log2(NK[1]) - math.log2(i+1))
    elif(i+1 >= NK[1]):
        value = 0
    else:
        value = int(math.log2(NK[1]) - math.log2(i+1)) + 1
    if(value < 0):
        value = 0
    answer[i] = Fraction(1, (NK[0] * (2**value)))
print(float(sum(answer)))