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())
prob=0
for i in range(1,N+1):
  score=i
  omote=0
  while 1<=score<=K-1:
    score=score*2
    omote+=1
  prob+=(1/N)*((1/2)**omote)
print(prob)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=[]
i=0
if k>1:
    while len(a)==0 or a[-1]!=1:
        a.append((k-1)//(2**i))
        i+=1
else:
    a.append(0)
n1=len(a)
if n>=k:
    s=(n-k+1)/n
    for i in range(n1):
        if i!=n1-1:
            s+=(a[i]-a[i+1])/(n*(2**(i+1)))
        else:
            s+=a[i]/(n*(2**(i+1)))
else:
    s=0
    for i in range(n1):
        if i!=n1-1 and a[i]>=n>a[i+1]:
            s+=(n-a[i+1])/(n*(2**(i+1)))
        elif i!=n1-1 and n>a[i+1]:
            s+=(a[i]-a[i+1])/(n*(2**(i+1)))
        elif n>=a[i]:
            s+=a[i]/(n*(2**(i+1)))
print(s)

Submission status: Accepted

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

ans=0
l=[]

for i in range(1,n+1):
        a=i
        for j in range(0,20):
                if a<=k-1:
                        a=a*2
                else:
                        l.append(j)
                        break
for k in l:
        ans+=(1/n)*(1/2)**k
print(ans)

Submission status: Accepted

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

r=[]
for i in range(1, N+1):
  temp=i
  counter=0
  while temp<K:
    temp*=2
    counter+=1
    
  r.append(counter)
    
print(sum([pow(0.5, r[i]) for i in range(N)])/N)

Submission status: Accepted

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

print(ans/n)

Submission status: Accepted

Solution code:
import math

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

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

print(sum(table))

Submission status: Accepted

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

print(p / N)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    res = 0.0
    for i in range(1, n + 1):
        if i >= k:
            res += 1 / n
            continue
        ii = i
        j = 0
        while ii < k:
            ii *= 2
            j += 1
        res += 1 / n / (2 ** j)
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for n in range(1, N+1):
    if n >= K:
        ans += 1.0
    else:
        tmp  = 1.0
        while n < K:
            tmp /= 2
            n   *= 2
        ans += tmp

ans /= N

print(ans)

Submission status: Accepted

Solution code:
# Dice and Coin
n, k = map(int, input().split())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n, k = [int(x) for x in input().split()]
result = 0
if n >= k:
    result += (n - k + 1) / n
    result += sum(1 / 2 ** math.ceil(math.log(k / i, 2)) for i in range(1, k)) / n
else:
    result = sum(1 / 2 ** math.ceil(math.log(k / i, 2)) for i in range(1, n + 1)) / n

print('%.12f' % result)

Submission status: Accepted

Solution code:
import math
n, k = [int(e) for e in input().split()]
m = math.ceil(math.log(k, 2))
if k <= n:
  result = sum(1 / 2 ** math.ceil(math.log(k / i, 2)) for i in range(1, k)) / n
  result += (n - (k - 1)) / n
else:
  result = sum(1 / 2 ** math.ceil(math.log(k / i, 2)) for i in range(1, n + 1)) / n
print('%.12f' % result)

Submission status: Accepted

Solution code:
import numpy as np
import math

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

K_list = [K]
tmp = K

for i in range(1, K):
    if tmp < 1:
        break
    else:
        tmp = tmp / 2
        tmp2 = math.ceil(tmp)
        K_list.append(tmp2)

KN_list = []
count = 0

for i in range(len(K_list)):
    if K_list[i] > N :
        count += 1
        pass
    elif K_list[i] == N:
        KN_list.append(K_list[i])
    else:
        KN_list.append(K_list[i])  
if N+1 not in KN_list:
    KN_list.insert(0, N+1)



ans = 0
for i in range(len(KN_list)-1):
    tmp = KN_list[i] - KN_list[i+1]
    tmp = tmp * (0.5**(i+count))
    ans += tmp

ans = ans/N

print(ans)

Submission status: Accepted

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

proba = 0
for gotvalue in range(1, N + 1):
    if gotvalue < K:
        proba += (0.5**ceil(log2(K / gotvalue))) / N
    else:
        proba += 1 / N
print(proba)

Submission status: Accepted

Solution code:
import math
import numpy as np

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

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

prob /= N
print(prob)

Submission status: Accepted

Solution code:
from math import log, ceil

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

ans = 0
mul2 = 2 ** ceil(max(log(K / N, 2), 0))
sum2 = 2 ** (ceil(log(K, 2)) - ceil(max(log(K / N, 2), 0)))

for i in range(N, 0, -1):
    if i * mul2 < K:
        mul2 *= 2
        sum2 //= 2
    ans += sum2

print(ans / (N * 2 ** ceil(log(K, 2))))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

win = 0

for t in range(1, min(K, N+1)):
    win += ((0.5)**(int(math.log2(K)-math.log2(t)-1e-10)+1))
win *= (1/N)

if N >= K:
    win += (N-K+1)/N
print(win)

Submission status: Accepted

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

Lmax = 1
Rmin = N

P = [0.0]*(N+1)

for i in reversed(list(range(1, N+1))):
    if i >= K:
        P[i] = 1/N
    elif i*2 > N:
        p = 1/N
        current_point = i
        while current_point < K:
            p *= 1/2
            current_point *= 2
        P[i] = p
    else:
        P[i] = P[i*2] * (1/2)


print(sum(P))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n,k = map(int,input().split())
	ans = frac(float(0))
	scala = frac(1,n)
	for i in range(1,n+1):
		if(i>k):
			ans += frac(float(1)) * scala
		else:
			ans += frac(1,2**(math.ceil(math.log(k/i,2)))) * scala
	print(float(ans))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Accepted

Solution code:
def main():
    N, K = list(map(int, input().split()))
    ans = 0
    for i in range(1, N+1):
        times = 0
        while(1):
            if (i * pow(2, times) >= K): break
            times += 1
        ans += (1.0/N) * pow(0.5, times)

    print(ans)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc126/tasks/abc126_c
# C - Dice and Coin

import math

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

# 全パターン
step_1_p_list = [1 / n for x in range(1, n+1)]

# サイコロを降る回数
step_2_p_list = []

for saikoro in range(1, n+1):
    if saikoro >= k:
        step_2_p_list.append(1)
        continue

    a, b = math.modf(math.log2(k/saikoro))
    if a == 0:
        must_win_n = b
    else:
        must_win_n = b + 1
    must_win_n = int(must_win_n)
    # sprint('saikoro = {}: ({}, {}) -> {}'.format(saikoro, a, b, must_win_n))
    # print('{}: must_win_n = {}'.format(saikoro, must_win_n))
    step_2_p_list.append((1/2) ** must_win_n)

# print('step_1: {}'.format(step_1_p_list))
# print('step_2: {}'.format(step_2_p_list))

p_list = []

for step_1_p, step_2_p in zip(step_1_p_list, step_2_p_list):
    p_list.append(step_1_p * step_2_p)

# print('p_list: {}'.format(p_list))
ans = sum(p_list)
print(ans)

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
def prob(n,k):
	if(n>=k):
		return 1
	else:
		return(0.5**(math.ceil(math.log(k/n,2))))
i=1
s=0
while(i<=n):
	s+=prob(i,k)
	i+=1

s/=n
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

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
    else:
        p += 0.5 ** math.ceil(math.log2(k/i))

print(p/n)

Submission status: Accepted

Solution code:
def prob(point, p, K):
    if point >= K:
        return p
    else:
        return prob(point * 2, p * 0.5, K)

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

p_arr = []
for i in range(N):
    dice = i + 1
    p_arr.append(prob(dice, 1/N, K))

print(sum(p_arr))

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
P_n = [0]*N
pro = 1.0
pow = 0
for i in range(N - 1, -1, -1):
	while (i+1)*(2**pow) < K:
		pow +=1
		pro /=2
	P_n[i] = pro

print(sum(P_n)/N)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
a = input().split()
a = [int(i) for i in a]

kakuritu = 0
for i in range(1, a[0] + 1):
    num = i
    kakuritu_count = a[0]
    while (True):
        if (num >= a[1]):
            break
        num *= 2
        kakuritu_count *= 2

    kakuritu += 1/kakuritu_count

print(kakuritu)

Submission status: Accepted

Solution code:
def win(i,k):
    t=0
    while i<k:
        i=i*2
        t+=1
    return t

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

for i in range(1,n+1):
    prob+=(1/n)*((1/2)**win(i,k))
print(prob)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

throw = [0 for i in range(N)]
times = 0
for i in range(N, 0, -1):

    while K / (i * 2 ** (times)) > 1:
        times += 1
    throw[i-1] = 1/N*pow(1/2, times)


# print(throw)
ans = 0
for i in throw:
    ans += i
print(ans)

Submission status: Accepted

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

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

print(p / N)

Submission status: Accepted

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

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

Submission status: Accepted

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

pro = 0

for i in range(1,min(N+1,K)):
	count = 1
	for _ in range(int(K**0.5)+1):
		if i * 2 < K:
			count += 1
			i = i * 2
	pro += (1/N) * (1/2) ** count

if N >= K:
	pro += (N-K+1)/N

print(pro)

Submission status: Accepted

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

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

print(ans/n)

Submission status: Accepted

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

m = math.ceil(math.log2(k) - math.log2(1))

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

a = (ans/(2**m)+ans_)/n
print(a)

Submission status: Accepted

Solution code:
import math

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

w = 0
for i in range(1,n+1):
    #k<=(2**j)*iとなるjについてw = w + (1/n) * (1/2)**j
    j = max(0,math.ceil((math.log((k/i),2))))
    w = w + (1/n) * (1/2)**j
print(w)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

    ans = 0
    for i in range(n):
        p = 1
        tokuten = i+1
        while k-1 >= tokuten:
            p /= 2
            tokuten *= 2
        ans += p/n

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
def count(x, y):
    cnt = 0
    while x < y:
        x = x * 2
        cnt += 1
    return(cnt)

p = [0 for _ in range(N)]
for i in range(1, N + 1):
    p[i - 1] = 0.5 ** count(i, K)
print(sum(p) / N)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
fund = 1/n
ans = 0
for i in range(1,n+1):
    if i >= k:
        ans += fund
    else:
        ii = i
        cond = 1
        temp = 0
        while cond:
            ii *= 2
            temp += 1
            if ii >= k:
                cond = 0
        ans += fund * ((1/2) ** temp)
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
tmp=0
for dice in range(1,n+1):
  points = dice
  cnt = 0
  while points<=k-1:
    points = points * 2
    cnt += 1
  tmp+=(0.5**cnt)/n
print(tmp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
ans = 0
for i in range(n):
    if i >= k:
        ans += 1/n
        continue
    ans += (1/n) * ( (0.5)**(math.ceil(math.log2(k/(i+1)))) )

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import math
n, k = (int(i) for i in input().split()) 
p = 0
for i in range(1,n+1):
  if i < k:
    x = math.ceil(math.log2(k/i))
    temp = 0.5 ** x / n
  else:
    temp = 1 / n
  p = p + temp
print(p)

Submission status: Accepted

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

coin = [0] * N
for i in range(len(coin)):
    cnt = 0
    v = i + 1
    while v < K:
        cnt += 1
        v *= 2
    coin[i] = cnt
    
ans = 0
for v in coin:
    ans += 0.5 ** v
print(ans / N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np


def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    exps = np.ceil(np.log2(np.ceil(K / np.arange(1, N+1))))
    ans = 1. / N * np.sum(0.5 ** exps)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

def GetCounts(number):
    cnt = 0
    quotient = K/number
    while(quotient>1):
        quotient /= 2
        cnt += 1
    return cnt

for i in range(N):
    probabilities[i] = (1/N)* pow(0.5,GetCounts(i+1))
print(sum(probabilities))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
import math
a=0
b=[]
c=0
d=[0 for i in range(n)]
for i in range(n,0,-1):
    while(True):
        if(pow(2,c)*i>=k):
            d[i-1]=c
            break
        c+=1
for i in range(n):
    a+=pow(2,d[0]-d[i])
print('{0:.10f}'.format(a/(pow(2,d[0])*n)))

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, K] = string_to_int(inputs[0])

    ret = 0.0
    for i in range(1, N+1):
        score = i
        count = 1
        tmp = 1.0 / N
        while score < K:
            score *= 2
            count += 1
            tmp *= 0.5
        ret += tmp

    return ret


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
l = list(range(1, n + 1))

count = 0
for i in range(len(l)):
    if l[i] < k:
        while True:
            l[i] = l[i] * 2
            count += 1
            if l[i] >= k:
                l[i] = (1 / n) * (0.5 ** count)
                count = 0
                break
    else:
        l[i] = (1 / n)
print(sum(l))

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
l = list(range(1, n + 1))
count = 0
for i in l:
    if i < k:
        while True:
            l[i - 1] = l[i - 1] * 2
            count += 1
            if l[i - 1] >= k:
                l[i -1] = (1 / n) * (0.5 ** count)
                count = 0
                break
    else:
        l[i -1] = (1 / n)
print(sum(l))

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
l = list(range(1, n + 1))

for i in l:
    if i < k:
        for r in range(1, 18):
            l[i - 1] = l[i - 1] * 2
            if l[i - 1] >= k:
                l[i -1] = (1 / n) * (0.5 ** r)
                break
    else:
        l[i -1] = (1 / n)
print(sum(l))

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = 0
for i in range(1, a+1):
    d = 0
    e = i
    while True:
        if e >= b:
            c += (1 / a) * (0.5 ** d)
            break
        d += 1
        e *= 2
print(c)

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
  else: 
    j = math.log(K/i,2)
    x = math.ceil(j)
    ans += (0.5)**x
   
win_rate = ans/N 
print(win_rate)

Submission status: Accepted

Solution code:
import math

N,K = map(int,input().split())
sum = 0
max2 = math.ceil(math.log2(K)) 
for i in range(1,N+1):

    #K ~ Nの時は、100％となる
    if i == K:
        sum += (2 ** max2) * (N-K+1)
        break

    R = math.ceil(math.log2(K / i))
    r = max2 - R

    sum += 2 ** r

mother = N * 2 ** max2
answer = sum/mother

print(answer)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
coins = []
for i in range(1, N+1):
	m = i
	cnt = 0
	while m < K:
		cnt += 1
		m *= 2
	coins.append(cnt)
p6 = 0
for i in range(0, N):
	p6 += 1 / (2**coins[i])
print(round(p6/N, 10))

Submission status: Accepted

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

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

print(sum_p)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    cnt = 0
    dice = i+1
    if(dice>=k):
        res = (n-dice+1)/n
        ans += res
        break
    for j in range(k):
        dice *= 2
        if(dice >= k):
            cnt += 1
            break
        elif(dice < k):
            cnt += 1        
    tmp  = 1/n * (1/2)**cnt

    ans += tmp

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

ret = 0
for i in range(1, N + 1):
    p = 1 / N
    if i < K:
        p *= 0.5 ** math.ceil(math.log2(K / i))
    ret += p

print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

    total_prob = 0.0
    for i in range(1, N+1):
        res = i
        prob = 1 / N
        while res < K:
            prob *= 0.5
            res *= 2

        total_prob += prob

    print(total_prob)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

# print(N)
# print(K)

A = 0
B = []

a = 0

for n in range(1, N+1):
    if K/n > 1:
        i = math.ceil(math.log2(K/n))
        a += 2 ** (N+1-i)
        B.append(a)
    else:
        a += 2 ** (N+1) * (N + 1-n)
        break

# for n in range(1, N+1):
#     if K/n <= 1:
#         i = 0
#     else:
#         i = math.ceil(math.log2(K/n))
#     a += 2 ** (N+1-i)

    #A += 1/(2**i)
# print(A)
# print(A*(1/N))

print(a/(2**(1+N))/N)

Submission status: Accepted

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

for i in range(1, N+1):
    tmp = 1.0 / N
    if i < K:
        point = i
        while point < K:
            point *= 2
            tmp /= 2
        result += tmp
    else:
        result += tmp

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

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):
    coins = max(math.ceil(math.log2(K / i)), 0)
    ans += 1 / (N * (2 ** coins))

print(ans)

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, K = LI()

exp = 0
for n in range(1, N + 1):
    # 2を何回かけたらKを超えるか計算する
    tmp = n
    count = 0
    while tmp < K:
        tmp *= 2
        count += 1
    exp += 1/N * (1/2)**count
print(exp)

Submission status: Accepted

Solution code:
import math

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

res = 0.0
for i in range(1, n+1):
  if not (k//i) == 0:
    if (k/i) == (k//i):
      if math.log2(k//i) == int(math.log2(k//i)):
        x = int(math.log2(k//i))
      else:
        x = int(math.log2(k//i)) + 1
    else:
      x = int(math.log2(k//i)) + 1
  else:
    x = 0
  res += (1/n) * (0.5 ** x)
print(res)

Submission status: Accepted

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

result = 0
for i in range(N+1)[1::]:
    prod = i
    cnt = 0
    if i >= K:
        result += (N - i + 1) / N
        break
    else:
        while True:
            prod *= 2
            cnt += 1
            if prod >= K:
                result += 1 / (N*(2**cnt))
                break
print(result)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,K = map(int, input().split())
bi = []
i = 1
j = 0
while i < K:
    bi.append(i)
    i *= 2
    j += 1
bi.append(i)
ans = max(0,N-K+1)
ite = min(N+1,K)

for i in range(1,ite):
    # print(i,j, bi[j-1] * i)
    if j > 0 and bi[j-1] * i >= K:
        j -= 1
    #print(i, j, i*bi[j])
    ans += 0.5**j
print('{:.10f}'.format(ans / N))

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
bi = []
i = 1
j = 0
while i < K:
    bi.append(i)
    i *= 2
    j += 1
bi.append(i)
ans = max(0,N-K+1)
ite = min(N+1,K)

for i in range(1,ite):
    # print(i,j, bi[j-1] * i)
    if j > 0 and bi[j-1] * i >= K:
        j -= 1
    #print(i, j, i*bi[j])
    ans += 0.5**j
print('{:.10f}'.format(ans / N))

Submission status: Accepted

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

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

        j += 1

print(result/n)

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().split())
from math import log, ceil
possibility = 0
ook = 1.0 / n
for d in range(1, n+1):
    if d >= k:
        exponent = 0
    else:
        exponent = int(ceil(log(float(k)/d, 2)))
    #print ook, exponent
    possibility += ook * (0.5)**exponent
print possibility

Submission status: Accepted

Solution code:

def bisect(bi, x, target, left, right):
    if left + 1 == right:
        return right
    half = (right + left) // 2
    if bi[half] * x < target:
        half = bisect(bi, x, target, half, right)
    else:
        half = bisect(bi, x, target, left, half)
    return half
N,K = map(int, input().split())
bi = []
i = 1
while i <= 10**5:
    bi.append(i)
    i *= 2
bi.append(i)

ans = 0
for i in range(1,N+1):
    if i >= K:
        ans += 1
    else:
        j = bisect(bi, i, K, 0, len(bi))
        ans += 0.5**j
print('{:.10f}'.format(ans / N))

Submission status: Accepted

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