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:
# coding: utf-8

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

counts = []

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

result = 0


for count in counts:
    result += (1 / n ) * ((0.5) ** count)

print(result)

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
p = 0
for n in range(1,N+1):
	if n >= K : p+= 1/N
	else:
		c = max(1, math.ceil(math.log(K/n,2)))
		p += ((1/2)**c)/N
print(p)

Submission status: Accepted

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

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

print(ans/N)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,N+1):
  if i >= K:
    ans=ans+1.0/N
    continue;
    
  hi=100
  lo=0
  while hi-lo>1:
    mid=(hi+lo)//2
    if i*(2**mid)>=K:
      hi=mid
    else:
      lo=mid
    
  ans=ans+1.0/N*(0.5**hi)
  
print(ans)

Submission status: Accepted

Solution code:
n,k = (int(i) for i in input().split()) 
kakuritu=0

for i in range(n):
    if i+1 >= k :
        kakuritu += 1/n
    elif i+1 < k:
        a=1
        while float(k) - (i+1)*pow(2,a) > 0:
            a += 1
        kakuritu += (1/n) * pow(1/2,a)
print(kakuritu)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0
for i in range(N):
    j = 0
    tmp = i + 1
    while tmp < K:
        tmp = tmp * 2
        j += 1
    sum += (1/N) * ((1/2)**j)
print(sum)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def f(n):
	count = 0
	while n * (2 ** count) < K:
		count += 1
	return count

P = 0
for n in range(1, N+1):
	P += ( 0.5 ** f(n) ) / N


print(P)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
coin_num_list = []
if N != K:
    for i in range(1, min(K, N+1)):
        dice_val = i
        j = 0
        while dice_val < K:
            dice_val *= 2
            j += 1
        coin_num_list.append(j)
else:
    for i in range(1, K):
        dice_val = i
        j = 0
        while dice_val < K:
            dice_val *= 2
            j += 1
        coin_num_list.append(j)
pro_sum = 0
for coin_val in coin_num_list:
    pro_sum += (1/2)**coin_val
if N >= K:
    print((N-K+1)/N + pro_sum/N)
else:
    print(pro_sum/N)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

# N: N面サイコロ
# K: 得点

p = max(0, (n - k + 1))

for x in range(1, min(n + 1, k)):
    m = 0
    y = x
    while True:
        y = y * 2
        m = m + 1
        if y >= k:
            break
    p += ((1 / 2) ** m)

print(p / n)

Submission status: Accepted

Solution code:
import math

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

total = 0
for i in range(n, 0, -1):
    
    cnt = 0
    temp = i
    while temp < k:
        temp *= 2
        cnt += 1
    
    power = math.pow(2, -cnt) / n
    total += power
    #print(i, cnt, power)

print(total)

Submission status: Accepted

Solution code:
import math
from decimal import *


def read():
    N, K = list(map(int, input().strip().split()))
    return N, K


def solve(N, K):
    # 得点nのとき、x回連続で表が出たらK以上になる
    getcontext().prec = 10
    prob = []
    for n in range(1, N+1):
        x = max(0, math.ceil(math.log2(K / n)))
        prob.append(Decimal.from_float(0.5) ** Decimal(x))
    return sum(prob) / Decimal(N)


if __name__ == '__main__':
    inputs = read()
    print("%.10f" % solve(*inputs))

Submission status: Accepted

Solution code:
import math

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

print(ans)

Submission status: Accepted

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

sum_rate = 0

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

    sum_rate += rate

print(sum_rate)

Submission status: Accepted

Solution code:
import math

n, k = map(int, raw_input().split(" "))

if n >= k:
    base = float(n - k + 1) / float(n)
else:
    base = 0

sum = base

for i in range(1, min(k, n + 1)):
    l = math.ceil(math.log(float(k) / float(i), 2))
    # print("i=%d l=%d" % (i, l))
    sum += (1.0 / float(n)) * (0.5 ** l)

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter
T = Counter()
N, K = map(int, input().split())
for i in range(1, N+1):
    T[(-1-(-K//i)).bit_length()] += 1
ans = 0
for k, v in T.items():
    ans += v*(1/2)**k
print(ans/N)

Submission status: Accepted

Solution code:
def main():
    n, k = list(map(int, input().split()))
    expect = 0
    for x in range(1, n + 1):
        if x > k - 1:
            expect += 1 / n
            continue
        n2w = 1
        for j in range(1, 100000):
            if x * (2**j) >= k:
                n2w = j
                break
        # print(f'n: {n} k: {k} x: {x} n2w: {n2w}')
        expect += (1 / n) * ((1 / 2) ** n2w)

    print(expect)


main()

Submission status: Accepted

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


def calc(ini):
    l = math.ceil(math.log2(K/ini))
    return 0.5**l


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

print(ans)

Submission status: Accepted

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

n = int(line[0])
k = int(line[1])

sum_p = 0
for i in range(n):
    score = i + 1
    p = 1 / n
    count = 0
    while score <= k - 1:
        score *= 2
        p /= 2
        count += 1
    sum_p += p
    
print('{:.12f}'.format(sum_p))

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
a = 0
for i in range(1, n + 1):
  t = int(math.ceil(math.log2(k / i)))
  t = 0 if t < 0 else t
  a += 0.5 ** t
  
print(a / n)

Submission status: Accepted

Solution code:
# 2019/05/19
# AtCoder Beginner Contest 126 - C

import math

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

# Init
bl = list()
for i in range(18):
    bl.append(2 ** i)

# Calc
ans = 0
for i in range(1, n + 1):

    for j in range(18):
        wval = i * bl[j]
        if wval >= k:
            break
    ans += (1 / n) * (1 / bl[j])

# Output
print(ans)

Submission status: Accepted

Solution code:
import sys
import math

N, K = map(int, sys.stdin.readline().split())

first = float(0)
if N >= K:
    first = float((N - K + 1)/N)

second = float(0)
if N >= K:
    for i in range(1, N+1):
        if i == K:
            break
        temp = float(math.log(K/i, 2))
        second += float(math.pow(1/2, math.ceil(temp)) * (1/N))
else:
    for i in range(1, N+1):
        temp = float(math.log(K/i, 2))
        second += float(math.pow(1/2, math.ceil(temp)) * (1/N))

ans = float(first + second)
print(ans)

Submission status: Accepted

Solution code:
from decimal import *
n,k = list(map(int,input().split()))
ans = Decimal(0)
if n > k-1:
    ans += Decimal((n-k+1)/n)
    for i in range(k-1):
        score = i+1
        cnt = 0
        while score <= k-1:
            score *= 2
            cnt += 1
        ans += Decimal((0.5**cnt)/n)
    print(ans)
else:
    for i in range(n):
        score = i+1
        cnt = 0
        while score <= k-1:
            score *= 2
            cnt += 1
        ans += Decimal((0.5**cnt)/n)
    print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

def min_v(x, k):
    v=1.0
    while v>x/k:
        v /= 2
    return v

V = 0
for n in range(1, N+1):
    V += min_v(n, K)

print('{:.16f}'.format(V/N))

Submission status: Accepted

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

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

p = []
for i in range(n):
    i = i+1
    if i>=k:
        p.append(1/n)
    else:
        # 何回2倍すればkを上回るか計算
        cnt = 0
        doubled_i = i
        while doubled_i<k:
            doubled_i *= 2
            cnt += 1
        p.append(1/n * 1/(2**cnt))

print(sum(p))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math

def solve(N: int, K: int):
    ans = .0
    for i in range(1,N+1):
        if(i <= K):
            t = math.ceil(math.log2(K/i))
            ans += (1/N) * (1/2) ** t
        else:
            ans += 1/N

    print(ans)
    
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

i = 1
while i <= num[0]:
    x = i
    y = 0
    while True:
        if x >= num[1]:
            break
        x = x * 2
        y += 1
    kakuritu_arr.append((1/num[0]) * (1/2) ** y)
    i +=1

result = 0
for temp in kakuritu_arr:
    result += temp
print(result)

Submission status: Accepted

Solution code:
import math

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

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

print(ans)

Submission status: Accepted

Solution code:
from fractions import Fraction

n, k = map(int, input().split())
r = Fraction(0, 1)

for i in range(n):
    m = i + 1
    l = 1
    while m < k:
        m *= 2
        l *= 2
    r += Fraction(1, l)

print(float(r * Fraction(1, n)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

p = (N-(K-1)) / N
if p < 0:
    p = 0
k = K
single_p = 1 / 2

while k >= 1:
    half = k / 2
    case = min(math.ceil(k), N+1) - math.ceil(half)
    # print(p, single_p, k, case)
    if case > 0:
        p += case / N * single_p
    single_p /= 2
    k /= 2

print(p)

Submission status: Accepted

Solution code:
from decimal import *

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

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

win=Decimal(0)
base_k=Decimal(1)/Decimal(n)
for i in range(1,n+1):
  if i < k:
    beki=count_beki(i,k)
    unq_k=(Decimal(1)/Decimal(2))**beki
    win+=base_k*unq_k
  else:
    win+=base_k

print(round(win,12))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d = 2
while k>n:
    d*=2
    k=(k+1)//2
ans = max(n-k+1,0)/d*2
while k>1:
    ans += (k//2)/d
    d *=2
    k = (k+1)//2
print(ans/n)

Submission status: Accepted

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

p = 0

for i in range(1,n + 1):
    if i > k:
        p += 1/n
    else:
        m = math.ceil(math.log(k/i,2))
        p += 1/n * (1/2)**m
print(p)

Submission status: Accepted

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

x = 0
t = 1
while x < K:
    x = N * (2 ** t)
    t += 1
t -= 1
per = 0
if N >= K:
    per += (1.0 / N)
else:
    per += (1.0 / N) * (0.5 ** t)

for i in range(1, N):
    v = N - i
    x = v * (2 ** t)
    while x < K:
        t += 1
        x = v * (2 ** t)
    if v >= K:
        per += (1.0 / N)
    else:
        per += (1.0 / N) * (0.5 ** t)
print(per)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


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

prob = 0

for dice in range(1, n+1):
	if dice >= k:
		prob += 1/n 
	else:
		prob += (1/n) * (1 / math.pow(2, (math.ceil(math.log2(k / dice)))))
		
print(prob)

Submission status: Accepted

Solution code:
import numpy as np
import math

def coin_prob(dice, score):
    num = math.ceil(np.log2(score/dice))
    return 1/(2 ** num)

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

if N >= K:
    base = (N - K + 1)/N
    for i in range(1,K):
        base = base + coin_prob(i, K)/N
else:
    for i in range (1,N + 1):
        base = base + coin_prob(i, K)/N
print(base)

Submission status: Accepted

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

for n in range(N, 0, -1):
    # get minimum t to trial
    while 2**t < K / n:
        t += 1
    inv_ans += 1 / 2**t

print(inv_ans / N)

Submission status: Accepted

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

ans=0
l=1
r=0
for z in range(1,N+1):
  l=0
  p=z
  while True:
    if p>=K:
      break
    p*=2
    l+=1
  if l==0:
    f=N
    #r=N-z
    #break
  else:
    f=N*2**l

  ans+=1/f

ans+=r

print(ans)

Submission status: Accepted

Solution code:
import sys
import math 
import numpy as np
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N,K=na()
n=N
k=10**9
cnt=0
if(N==1):
    if(K==1):
        print(1)
        exit()
    else:
        ans=0
        while(N<K):
            ans+=1
            N*=2
            #print(N)
        print(0.5**ans)
        exit()
while(N<K):
    #print(N,K)
    K=math.ceil(K/2)
    cnt+=1
k=K

ans=0
first=True
while(True):
    if(first):
        ans+=(N-k+1)*(0.5**cnt)
        first=False
    else:
        ans+=(N-k)*(0.5**cnt)

    #print("ddd",(N-k+1)*(0.5**cnt),"N",N,"k",k,"n-k+1",N-k+1,"cnt",cnt)
    #print("ans",ans)
    cnt+=1
    N=k
    k=math.ceil(k/2)
    #print("k",k)
    if(k==1):
        ans+=1*(0.5**cnt)
        #print("ddd",1*(0.5**cnt))
        #print("cnt",cnt)
        break
#print(ans,n)
ans=ans/n
print(ans)

Submission status: Accepted

Solution code:
import math
from math import log2
from math import ceil

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

def prob_wins(x,k):
    if x>=k:
        return 1
    return 0.5**ceil(log2(k/x))

ans = 0
for i in range(1,N+1):
    ans += prob_wins(i,K)
    # print(i,prob_wins(i,K))
print(ans/N)

Submission status: Accepted

Solution code:

# coding: utf-8

# In[6]:

import sys
input = sys.stdin.readline
N, K = map(int, input().split())
#S = input()


# In[2]:

import math


# In[14]:

#print(N, K)


# In[15]:

sum_ = 0
R = min(N, K)
clear = N-K+1 if N>=K else 0
R = R-1 if N>=K else R
#print('R = {}'.format(R))
for i in range(R):
    #print(math.ceil(math.log(K/(i+1), 2)))
    sum_ += (1/2) ** math.ceil(math.log(K/(i+1), 2))


# In[16]:

#print(clear/N)
print(round(1/N*sum_ + clear/N, 16))


# In[ ]:

Submission status: Accepted

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

Submission status: Accepted

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

P = 0
for i in range(N):
    i += 1
    c = 0
    while i <= K-1:
        i *= 2
        c += 1
    P += (0.5**c)/N

print(P)

Submission status: Accepted

Solution code:
import math

n, k = map(int,input().split())
log_k = math.log2(k)
p = 0

for i in range(1,n+1):
    j = math.ceil(log_k - math.log2(i))
    if j<0:
        j = 0
    p += (1/n)*(1/2)**j

print(p)

Submission status: Accepted

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

#1,2,4,8,16...
# max coin num
ans = 0


for i in range(1, N+1):
    coin = math.log2(K/i)
    if coin > 0:
        if coin % 1 == 0:
            coin = int(coin)
        else:
            coin = int(coin) + 1
        ans += (0.5) ** coin
    else:
        ans += 1
    
    

# ans = (1/N) * (1 - (2 ** N))  * (0.5 ** max_coin) * (-1)
# ans = (1/N) * ((math.exp(N*math.log(2))) -1)  * (0.5 ** max_coin)
print(ans/N)

Submission status: Accepted

Solution code:
import numpy as np

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

L = np.arange(N)
L += 1

count = np.sum(L >= K)
times = 1

prob = times * count

while count < N:
  times += 1
  old_count = count
  L *= 2
  count = np.sum(L >= K)
  prob += (count - old_count)*(0.5)**(times-1)
prob /= N
print(prob)

Submission status: Accepted

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

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

if n >= k:
    p += (n - k + 1)/n
print(p)

Submission status: Accepted

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

for n in range(1,N+1) :
    if n >= K :
        total += 1.0 / N
    else :
        total += (1.0 / N) * 0.5 ** math.ceil(math.log2(1.0 * K / n))
print(total)

Submission status: Accepted

Solution code:
n,k=[int(i) for i in input().split()]
ans=0
hoge=1
while hoge<k:
    hoge*=2
for i in range(1,n+1):
    while i*hoge//2>=k:
        if hoge==1.0:
            break
        hoge/=2
    ans+=(1/n)*(1/hoge)
    #print(hoge)
print(ans)

Submission status: Accepted

Solution code:
from math import ceil, log
n, k = map(int, input().split())
if n > k:
    ans = (n-k)/n
    o = k
else:
    ans = 0
    o = n

for i in range(1, o+1):
    ans += 1 / (n * 2 ** ceil(log(k/i, 2)))
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())  # 1~Nが出るようなN面のサイコロ, そして得点がKより小さい限りコインを投げる

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

    while K > i:
        i *= 2
        cnt += 1

    if cnt == 0:
        ans += 1
    else:
        ans += 1/(2**cnt)

print(ans/N)

Submission status: Accepted

Solution code:
import math
import decimal
n,k=list(map(int,input().split()))
#出た目がk以上 1
#k/2以上 1/2
#k/4以上 1/4
a=decimal.Decimal(0)

for i in range(n):
  if i>=k:
    a+=1
  else:
    a+=(decimal.Decimal(1/2)**abs(math.floor(math.log2((i+1)/k))))
print(a/n)

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
list2 = [1]
tmp = 1
while tmp < 10 ** 5 + 1:
    tmp *= 2
    list2 += [tmp]

L2 = len(list2)
ans = 0
for i in range(1,N+1):
    tmp = math.ceil(K/i)
    
    for j in range(L2):
        if tmp <= list2[j]:
            break
    ans += list2[j] ** (-1)
ans /= N
print(ans)

Submission status: Accepted

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

i = 0
foo = 0.0

arr = []

for n in range(a[0]):
    x = a[0] - n
    while (x * 2 ** i < a[1]):
        i += 1
    arr.append(i)

for i in arr:
    foo += 0.5 ** i

result = foo * (1 / a[0])

print(result)

Submission status: Accepted

Solution code:
import math


# さいころの目を受け取り，勝つ確率を出力する
def win_p(number, k):
    if number > k - 1:
        return 1
    if number == 0:
        return 0
    log_n = math.log((k/number), 2)
    int_log = int(log_n)
    if int_log < log_n:
        int_log += 1
    return math.pow(0.5, int_log)


inp = input()
st_sp = inp.split()
n = int(st_sp[0])
k = int(st_sp[1])
sum_p = 0.0
for i in range(n):
    sum_p += win_p(i+1, k)
print(sum_p/n)

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
x = 0
for i in range(1, N + 1, 1):
	a = math.ceil(math.log(float(K) / i, 2))
	if a < 0:
		a = 0
	x += float(1) / (2 ** a)
print(float(x) / N)

Submission status: Accepted

Solution code:
N,K=map(int, input().split())
ans = 0.0
for i in range(1,N+1):
  Z = 0
  S = i
  while True:
    if K <= S:
      break
    Z += 1
    S = S * 2
  ans += (1.0 / N) * pow(0.5, Z)
print(ans)

Submission status: Accepted

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

flag = True
check = []
a = 1
while flag:
    check.append(a)
    a *= 2
    if a >= 10 ** 5:
        flag = False
        
ans = 0
for i in range(1, N+1):
    count = 0
    for j in check:
        if j * i >= K:
            break
        count += 1
    ans += 1 / N * 0.5 ** count
print(round(ans, 12))

Submission status: Accepted

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

prop = 0.0
_prop = 0.0

if n >= k:
    _prop = (n - k) / n

end = min(n, k) + 1
for i in range(1, end):
    dest = k / i
    coin = math.ceil(math.log2(dest))
    __prop = (1 / n) * (1 / pow(2, coin))
    prop += __prop

print(prop + _prop)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import math
n, k = map(int, raw_input().split())
X = []
i = 1
while i <= n:
    x = max(math.ceil(math.log((float(k) / float(i)), 2)), 0)
    X.append(2 ** (-int(x)))
    i += 1
print sum(X) * n ** (-1)

Submission status: Accepted

Solution code:
import math
from fractions import Fraction
n,k=map(int,input().split())
if n>=k:
	result = (n-k+1)/n
else:
	result = 0
for i in range(1,min(n+1,k)):
	if math.log(k/i,2)==int(math.log(k/i,2)):
		time = int(math.log(k/i,2))
	else:
		time = int(math.log(k/i,2))+1
	result+=float(Fraction(1, n)*(Fraction(1, 2)**(time)))
print(result)

Submission status: Accepted

Solution code:
import math

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

per = 0
for i in range(1,n+1):
    p = i
    t = 0
    
    while(p < k):
        t += 1
        p = p*2
#        print(i,p,t)
    
    if(t == 0):
        t = 0
#        print(i,p,t)

        
    per +=1/n * (1/2 ** t)
    
print("{:}".format(per))

Submission status: Accepted

Solution code:
import math

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

naru = 0

for i in range(1, N+1):
    if i >= K:
        naru += 1
    else:
        kaisuu = math.ceil(math.log2(K / i))
        naru += 0.5 ** kaisuu

print("{:.12f}".format(naru / N))

Submission status: Accepted

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

C = [math.ceil(math.log2((K - 1) // i + 1)) for i in range(1, N + 1)]
maxC = max(C)

P = [1.0] * (maxC + 1)
for i in range(1, maxC + 1):
    P[i] = P[i - 1] * 0.5

S = 0.0
for c in C:
    S += P[c]
print(S / N)

Submission status: Accepted

Solution code:
from math import log
n,k=map(int,input().split())
if n<k:
    p=0
    for i in range(1,n+1):
        po=int(log(k/i,2))
        if i*(2**po)!=k:
            po+=1
        p+=(1/n)*((1/2)**po)
    print(p)
else:
    p=(n-k+1)/n
    for i in range(1,k):
        po=int(log(k/i,2))
        if i*(2**po)!=k:
            po+=1
        p+=(1/n)*((1/2)**po)
    print(p)

Submission status: Accepted

Solution code:
import math
n, k = [int(item) for item in input().split()]
max_n_k = max(n,k)
tk = k

logs = [0] * (max_n_k+1)
cnt = 0
while tk > 1:
    tk /= 2.0
    cnt += 1
    logs[int(math.ceil(tk))] = cnt 

cur = 0
for i in range(k+1):
    if logs[i] == 0 and i != k:
        logs[i] = cur
    if i == k:
        logs[i] = 0
        cur = 0
    else:
        cur = logs[i]

ans = 0
for i in range(1, n+1):
    ans += 1.0 / n * pow(0.5, logs[i])
print(ans)

Submission status: Accepted

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

if N >= K:
    p = N - K + 1
else:
    p = 0

for n1 in range(1, min(N+1,K)):
    p += pow(1/2, math.ceil(math.log(K/n1)/math.log(2)))

print("{:>.20f}".format(p/N))

Submission status: Accepted

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

times_dic = {}
for i in range(1,N+1):
  times = 0
  if i < K:
    times = math.ceil(math.log2(K/i))

  if times not in times_dic:
    times_dic[times] = 1
  else:
    times_dic[times] += 1
  
prob=0  
for times in times_dic:
  prob += 0.5**times*times_dic[times]/N
print(prob)

Submission status: Accepted

Solution code:
from fractions import *

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


a = Fraction(0, 1)
for t in range(1, N + 1):
    c = 0
    while t < K:
        t *= 2
        c += 1
    a += Fraction(1, 2 ** c)

print("{:.12f}".format(a.numerator / (N * a.denominator)))

Submission status: Accepted

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

P = 0

for dice in range(1,N+1):
    d = dice 
    prob = 1/N

    while d < K:
        prob = prob*0.5
        d *= 2

    P += prob


print(P)

Submission status: Accepted

Solution code:
n,k = list(map(int,input().split()))
p=0
for i in range(1,n+1):
    nage=0
    for j in range(19):
        if i>=k:
            nage = 0
        elif k<=i*2**j and i*2**(j-1)<k:
            nage=j
    p=p+(1/n)*(1/2**nage)
print(p)

Submission status: Accepted

Solution code:
from math import *

n, k = [int(item) for item in input().split()]
ans = 0
for p in range(1, n + 1):

    if p >= k:
        ans += 1;
    else:
        x = ceil(log2(k) - log2(p))
        ans += 1.0 / (1 << x);
print(ans / n)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math


def solve(N: int, K: int):
    ans = 0.0
    for i in range(1, N+1):
        n = math.ceil(math.log2(K/i))
        n = max(n, 0)
        ans += 1.0/(2**n)/N
    print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()