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: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

from math import log2, ceil

def solve():
    n, k = MI()

    ans = 0
    m = ceil(log2(k))

    sm = 0
    v = 0
    for point in range(1, n+1):
        if 1 <= point < k:
            # さいころを振る
            # print(point)
            sm = sm + 1
            for j in range(m+1):
                point = point * 2
                # print('  j+1', j+1, point)
                if point >= k:
                    # print(j)
                    if j != 0:
                        ans = ans + 1 / (pow(2, j+1))
                    break
        else:
            # 無条件で勝利
            v = v + 1
    t = v / n
    print(ans * (1 - t) / sm + t)


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, k = LI()
    s = S()
    s[k-1] = s[k-1].lower()
    print("".join(s))

    return

#B
def B():
    s = S()
    a = int("".join(s[:2]))
    b = int("".join(s[2:]))
    if 0 < a <= 12:
        if 0 < b <= 12:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    elif a == 0:
        if 0 < b <= 12:
            print("YYMM")
        else:
            print("NA")
    else:
        if 0 < b <= 12:
            print("YYMM")
        else:
            print("NA")
    return

#C
def C():
  	def log2(k):
      tmp = 0
      while k:
        k //= 2
        tmp += 1
      return tmp
    n, k = LI()
    ans = 0
    if k == 1:
        print(1)
        return
    nibuiti = [None for i in range(log2(k))]
    for num in range(log2(k)):
        if num == 0:
            nibuiti[num] = 1 / 2
            continue
        nibuiti[num] = nibuiti[num-1]/2
        
    for i in range(1, n + 1):
        if i >= k:
            ans += 1
            continue
        b = nibuiti[log2((k - 1) // i)]
        ans += b
    print(ans/n)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, k = LI()
    s = S()
    s[k-1] = s[k-1].lower()
    print("".join(s))

    return

#B
def B():
    s = S()
    a = int("".join(s[:2]))
    b = int("".join(s[2:]))
    if 0 < a <= 12:
        if 0 < b <= 12:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    elif a == 0:
        if 0 < b <= 12:
            print("YYMM")
        else:
            print("NA")
    else:
        if 0 < b <= 12:
            print("YYMM")
        else:
            print("NA")
    return

#C
def C():
    n, k = LI()
    ans = 0
    if k == 1:
        print(1)
        return
    nibuiti = [None for i in range(k.bit_length())]
    for num in range(k.bit_length()):
        if num == 0:
            nibuiti[num] = 1 / 2
            continue
        nibuiti[num] = nibuiti[num-1]/2
        
    for i in range(1, n + 1):
        if i >= k:
            ans += 1
            continue
        b = nibuiti[((k - 1) // i).bit_length()]
        ans += b
    print(ans/n)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Runtime Error

Solution code:
import math
#負けを考える

n, k = map(int, input().split())
if k == 1:
    p = 1
    print(p)
else:
    h = math.floor(math.log2(k - 1))

    p = 0

    s = [k - 1]
    for i in range(h):
        s.append(math.floor((k - 1) / (2 ** (i + 1))))
    s = s[::-1]
    t = [s[0]]
    for j in range(h):
        t.append(s[j + 1] - s[j])

    t = t[::-1]
    for i in range(len(t)):
        p += t[i] * ((1 / 2) ** (i + 1)) * (1 / n)

    p += (n + 1 - k) / n

    print(p)

Submission status: Runtime Error

Solution code:
import math
#負けを考える

n, k = map(int, input().split())
h = math.floor(math.log2(k-1))

p = 0

s = [k-1]
for i in range(h):
    s.append(math.floor((k-1) / (2**(i+1))))
s = s[::-1]
t = [s[0]]
for j in range(h):
    t.append(s[j+1] - s[j])

t = t[::-1]
for i in range(len(t)):
    p += t[i] * ((1/2)**(i+1)) * (1/n)

p += (n+1-k)/n

print(p)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    if i >= k:
        ans += 1/n
    else:
        if k//i == 0 :
            num = 1
        else:
            num = int((np.log2(k/i)+1)//1)
        ans += (1/n)*(1/2)**num
    
print(ans)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    if i >= k:
        ans += 1/n
    else:
        if k//i == 0 :
            num = 1
        else:
            num = int((np.log2(k//i)+1)//1)
        ans += (1/n)*(1/2)**num
    
print(ans)

Submission status: Runtime Error

Solution code:
import collections, math, bisect
from decimal import *

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()

getcontext().prec = 15

N, K = ints()

oneprob = 1/N
ans = 0
for i in range(1, N+1):
    if i>=K:
        break
        
    doubling_amounts = math.ceil(math.log2(K/i))
    ans+=0.5**doubling_amounts

ans*=oneprob

if N>K:
    ans+=(N-K) / N

print(ans)

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

pow2 = [1]
for i in range(1, k):
    pow2.append(pow2[i-1]*2)
win = 0
for i in range(1, n+1):
    for j, x in enumerate(pow2):
        if x > k/i:
            index = j
            break
    win += pow(1/2, index)
print(win/n)

Submission status: Runtime Error

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

pow2 = [1]
for i in range(1, k):
    pow2.append(pow2[i-1]*2)
win = 0
for i in range(1, n+1):
    for j, x in enumerate(pow2):
        if x > k/i:
            index = j
            break
    bunbo = pow(2, index)
    win += 1/bunbo
print(win/n)

Submission status: Runtime Error

Solution code:
import math
from fractions import Fraction

ans = 0
N, K = map(int, input().split())
for i in range(N):
	ans += Fraction(1,N)*Fraction(1,2**math.ceil(math.log2(K/(i+1))))
print(float(ans))

Submission status: Runtime Error

Solution code:
import math

ans = 0
N,K = input().split()
for i in range(N):
	ans += Fraction(1,N)*Fraction(1,math.ceil(math.log2(K/(i+1))))
print(float(ans))

Submission status: Runtime Error

Solution code:
import math

ans = 0
N,K = input().split()
for i in range(N)
	ans += Fraction(1,N)*Fraction(1,math.ceil(math.log2(K/(i+1))))
print(float(ans))

Submission status: Runtime Error

Solution code:
dice_num = int(input_num[0])
border_socre = int(input_num[1])
ans_p = 0

for score in range(1,dice_num + 1):
    coin_counter = 0
    
    while score <= border_socre:
        score = score * 2
        coin_counter += 1
    ans_p += (1 / dice_num ) * (1/2 ) ** coin_counter
print(ans_p)

Submission status: Runtime Error

Solution code:
prob = 0
#サイコロの確率(1/n) 

for i in range(1,n+1):
    if i < k: #サイコロを振った時点で勝っているか？
        a = 1
        while i * (2**a) < k:
            a += 1
        prob += (1/n) * ((1/2) ** a)
    else:
        prob += (1/n)
print(prob)

Submission status: Runtime Error

Solution code:
c=0
def doublet(n,f):
    global c
    if n<f:
        c=c+1
        return doublet(2*n,f)
    else:
        return c
num=eval(input())
k=eval(input())
if (num>=1 and num<=10**5) and (k>=1 and k<=10**5):
    sum_power=0.0
    for i in range(1,(num+1),1):
        count=doublet(i,k)
        p=pow(2,count)*num
        sum_power=sum_power+(1/p)
        c=0
    print(sum_power)

Submission status: Runtime Error

Solution code:
c=0
def doublet(n,f):
    global c
    if n<f:
        c=c+1
        return doublet(2*n,f)
    else:
        return c
num=eval(input("n= "))
k=eval(input("k="))
sum_power=0.0
for i in range(1,(num+1),1):
    count=doublet(i,k)
    p=pow(2,count)*num
    sum_power=sum_power+(1/p)
    c=0
print(sum_power)

Submission status: Runtime Error

Solution code:
import math
n,k = map(int,input().split())
sumlist = []
for i in range(1,n+1):
  point = i
  if point <= k-1:
    s = math.log2(k/i)
    if s == int(s):
      sumlist.append((1/2)**(int(s)))
    else:
      sumlist.append((1/2)**(int(s)+1))
  else:sumlist.append(1)
print(round(sum(sumlist)/n,10)-10**(-10))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
n,k = map(int,input().split())
sum = 0
for i in range(1,n+1):
  point = i
  if point <= k-1:
    s = math.log2(k/i)
    if s == int(s):
      sum += (1/2)**(int(s))
    else:
      sum += (1/2)**(int(s)+1)
  else:sum += 1
print(round(sum/n,10)-10**(-10))

Submission status: Runtime Error

Solution code:
import math
n,k = map(int,input().split())
sum = 0
for i in range(1,n+1):
  point = i
  if point <= k-1:
    s = math.log2(k/i)
    if s == int(s):
      sum += (1/2)**(int(s))
    else:
      sum += (1/2)**(int(s)+1)
  else:sum += 1
print(round(sum/n,10))

Submission status: Runtime Error

Solution code:
N,K =  [int(x) for x in input().split()]
num = 1
while num < K:
    num *= 2

L = [0.0000]*N

for i in range(N):
    if N < K:
        if num/(i+1) < K:
            num = num/2
        L[i]= 1/N * 1/num    
    else:
        L[i] = 1/N

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

print(ans)

Submission status: Runtime Error

Solution code:
if n<k:
    for i in range(1,n+1):
        a=i
        cnt=1
        while(i+a<k):
            a=a**2
            a+=1
            cnt+=1
        ans+=1/n*(1/2)**cnt
else:
    b=n-k
    ans+=b/n
    for i in range(1,k+1):
        c=i
        cnt=1
        while(i+c<k):
            c=c**2
            c+=1
            cnt+=1
        ans+=1/n*(1/2)**cnt
print(ans)

Submission status: Runtime Error

Solution code:
if n<k:
    for i in range(1,n+1):
        a=i
        cnt=1
        while(i+a<k):
            a=a**2
            a+=1
            cnt+=1
            print(cnt)
        ans+=1/n*(1/2)**cnt
        print(ans)
else:
    b=n-k
    ans+=b/n
    for i in range(1,k+1):
        c=i
        cnt=1
        while(i+c<k):
            c=c**2
            c+=1
            cnt+=1
            print(cnt)
        ans+=1/n*(1/2)**cnt
    


print(ans)

Submission status: Runtime Error

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

p1=(N-K)/N
klist=list(range(1,K+1))

def calc(x, K):
  y=math.ceil((np.log(K)-np.log(x))/np.log(2))
  p=x*(0.5)**y
  
  return p

plist=map(calc, klist)
p2=sum(plist)
print(p1+p2)

Submission status: Runtime Error

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

p1=(N-K)/N
klist=list(range(1,K+1))

def calc(x, K):
  y=math.floor((np.log(K)-np.log(x))/np.log(2))
  p=x*(0.5)**y
  
  return p

plist=map(calc, klist)
p2=sum(plist)
print(p1+p2)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=[]
def x(t,k):
  c=0
  while t<k:
    t*=2
    c+=1
  return c

for i in range(n):
  a.append(x(i+1),k)

ans=0
for i in range(n):
  ans=ans+1/n*(1/2)**a[i]
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=[]
def x(t,k):
  c=0
  while t<k:
    t*=2
    c+=1
  return c

for i in range(n):
  a.append(x(i+1),k)

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

Submission status: Runtime Error

Solution code:
n,k=int(input().split())
a=[]
def x(t,k):
  c=0
  while t<k:
    t*=2
    c+=1
  return c

for i in range(n):
  a.append(x(i+1),k)

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

Submission status: Runtime Error

Solution code:
n,k=int(input().split())
a=[]
def x(t,k):
  c=0
  while t<k:
    t*=2
    c+=1
  return c

for i in range(n):
  a.append(x(i+1),k)

ans=0
for i in range(k):
  ans=ans+1/6*(1/2)**k
print(ans)

Submission status: Runtime Error

Solution code:
n,k=int(input().split())
a=[]
def x(n,k):
  c=0
  while n<k:
    n*=2
    c+=1
  return c

for i in range(n):
  a.append(x(i+1),k)

ans=0
for i in range(k):
  ans=ans+1/6*(1/2)**k
 
print(ans)

Submission status: Runtime Error

Solution code:
from math import *
n,k=map(int,input().split())
e=0
for i in range(1,n+1):
  t=ceil(log2(k/i))
  e+=1*(m<1)or 2**-t
print(e/n)

Submission status: Runtime Error

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

points=[]
for i in range(N):
    x=K/(i+1)
    y=math.log(x)/math.log(2)
    y=max(0,math.ceil(y))
    z=pow(2,-math.ceil(y))
    points.append(z)
print(sum(points)/N)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
s=[]
t=0
for i in range(1,N+1):
  if i<K:
    while t<(math.log2(K)-math.log2(i)):
      t+=1
    else:
      t=t
      k=(1/N)*(1/2)**t
      s.append(k)
      break
  else:
    s.append(1/N)
    continue
print(sum(s))

Submission status: Runtime Error

Solution code:
import math
N,K=map(int,input().split())
s=[]
t=1
for i in range(1,N+1):
  if i<K:
    while t<math.log2(K)-math.log2(i):
      t+=1
    else:
      s.append((1/N)*(1/2)**t)
      break
  else:
    s.append(1/N)
print(sum(s))
import math
N,K=map(int,input().split())
s=[]
t=0
for i in range(1,N+1):
  if i<K:
    while t<math.log2(K)-math.log2(i):
      t+=1
    else:
      s.append((1/N)*(1/2)**t)
      break
  else:
    s.append(1/N)
print(sum(s))

Submission status: Runtime Error

Solution code:
import math
N,K=map(int,input().split()))
s=[]
t=1
for i in range(1,N+1):
  if i<K:
    while t<math.log2(K)-math.log2(i):
      t+=1
    else:
      s.append((1/N)*(1/2)**t)
      break
  else:
    s.append(1/N)
print(sum(s))

Submission status: Runtime Error

Solution code:
import sys 
readline = sys.stdin.buffer.readline
N,K = map(int, readline().split())
l = [2**i for i in range(1,15)]
ans = 0
for i in range(1,N+1):
  for j in 1:
    if i*j < K:
      continue
    else:
      ans += 1/N + 1/j 
      break
print(ans)

Submission status: Runtime Error

Solution code:
import math as mt
N,K = [int(i) for i in input().rstrip().split()]
R = 0
for n in range(1,N+1):
    l = mt.floor(mt.log2((K-1)/n))+1
    if l <= 0:
        R += 1/N*(N-n+1)
        #print(K,n,l,R)
        print(R)
        break
    else:
        R += 1/N*0.5**l
        #print(K,n,l,R)

Submission status: Runtime Error

Solution code:
N,K=map(int, input().split())
p=[]
for num in range(N):
  for i in range(500):
    if( (num+1)*(2**(i+1)) < K):
      p.append(1/(N*2**(i+1))
      continue
ptint(sum(p))

Submission status: Runtime Error

Solution code:
N = int(input())
K = int(input())
point = 0
for i in range(1,N+1):
  for j in range(N):
    if  i**j >= K:
      point += (1/N)*(1/2)**j
      i += 1
    else:
      j += 1
print(point)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
K = int(input())
win = [0]
win = np.array(win,dtype=np.float64)
for i in range(1,N+1):
  for j in range(N):
    if  i**j >= K:
      win[i] = (1/N)*(1/2)**j
      i += 1
    else:
      j += 1
ans = sum(win)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
K = int(input())
win = [0]
win = np.array(win)
point = 0
for i in range(1,N+1):
  for j in range(1,K):
    if  i**j >= K:
      win[i] = (1/N)*{(1/2)**j}
      i += 1
    else:
      j += 1
ans = sum(win)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
K = int(input())
win = []
win[0] = 0
point = 0
for i in range(1,N+1):
  for j in range(1,K):
    if  i**j >= K:
      win[i] = (1/N)*{(1/2)**j}
      i += 1
    else:
      j += 1
ans = sum(win)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
# 最終的に出力する色
colors = [-1] * n
# 重み付き無向グラフ
conns = [set() for _ in [0] * n] 

for x in range(1, n):
  v1, v2, dis = map(int, input().split())
  # (接続ノード, 重み) を加える
  conns[v1-1].add((v2-1, dis))
  conns[v2-1].add((v1-1, dis))

# BFSの為に根ノードを初期化. (基準ノード, 距離)
q = deque([(0, 0)])
# BFS開始
while q:
  v, dis, past = q.popleft()
  
  # 奇数なら1で,偶数なら0で塗る
  colors[v] = dis&1
  
  # 基準ノードから生える各エッジに対し
  for edge, w in conns[v]:
    
    # 根からここまでの距離を足しつつ,新しく探索先を追加.
    q.append((edge, dis + w))

print('\n'.join(map(str, colors)))

Submission status: Runtime Error

Solution code:
3
5 2 4

Submission status: Runtime Error

Solution code:
import os, sys, re, math

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

lk = math.log2(K - 1)

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

print(p / N)

Submission status: Runtime Error

Solution code:
import os, sys, re, math

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

lk = math.log2(K - 1)

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

print(p / N)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
tmp = K/N
q = 1
p = 2 ** 100
while p/q >2:
    qp = q*2
    if qp > tmp:
        p = qp
    else:
        q = qp
for i in range(N,0,-1):
    ans = i*q
    if ans < K:
        q*=2
    res+= float(1)/q
print(res/N)

Submission status: Runtime Error

Solution code:
S=input()
sf=int(S[:2])
sb=int(S[3:])
if 1<=sf and sf<=12:
  if 1<=sb and sb<=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 1<=sb and sb<=12:
    print("YYMM")
  else:
    print("NA")

Submission status: Runtime Error

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

import math
ans=0
for m in range(1,n+1):
    if m>=k:
        l=0
    else:
        l=math.ceil( math.log2(k/m) )
    ans+=(0.50)**l /n
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
ans=0
import math
for i in range(1,n+1):
    x=math.log2(k)-math.log2(i)
    if x<=0:
        ans+=1
        continue
    if x.is_integer():
        ans+=1/(2**x)
    else:
        ans+=1/(2**(int(x)+1))
print(ans/n)

Submission status: Runtime Error

Solution code:
#salmonize の文
n,k = map(int,input().split()) 
 #複数文字の入力
ans = 0

for i in range(1,n+1):
j=0 
  #カウンター設置
  while i<k:
    i*=2
    j+=1
  ans=1/2**j
print("{:.12}".format(ans/n))

Submission status: Runtime Error

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

prob = 0

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

Submission status: Runtime Error

Solution code:
import math
import heapq
import sys
from collections import Counter
import numpy as np
import datetime

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#s = [input() for i in range(3)]

N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
li = []

for i in range(1,n+1):
    a=0
    while i*(2**a)<k:
        a+=1
    li.append((1/n)*(1/2**a))
    
print(sum(li))

Submission status: Runtime Error

Solution code:
import math

n, k = map(int, input().split())
# n < k の場合も考える必要がある

p = 0
for i in range(1, n+1):
    tmp = (n**-1)*(0.5)**int(math.log2(k//i) + 1)
    p+=tmp

print(p)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

MOD = 10 ** 9 + 7


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

    for i in range(1, N+1):
        c = 0
        if i < K:
            c = math.ceil(math.log2(K) - math.log2(i))
        # print(i, c, (1.0 / (2 ** c)), 1.0/N)
        ans += (1.0 / (2 ** c)) * 1.0/N

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

M = []
x = 1
while x < (10 ** 5) * 2:
    M.append(1 / x)
    x <<= 1

p1 = max((N - K + 1) / N, 0)
p = 0
for i in range(1, min(N + 1, K)):
    t = int(math.log2(K / i)) + 1
    if K % i == 0 and  (K // i) & (K // i - 1) == 0:
        t -= 1
    p += M[t]
ans = p / N + p1
print('{0:.10f}'.format(ans))






#*1/N

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
import math
s=N
q=0 #qは０点になる場合の数
if N>=K:
  for i in range(K):
    if (K//i)%2!=0:
      q+=int(math.log(K//i,2))+1
    else:
      q+=int(math.log(K//i,2))
else:
  for i in range(N+1):
    if (K//i)%2!=0:
      q+=int(math.log(K//i,2))+1
    else:
      q+=int(math.log(K//i,2))
print(s/(s+q))

Submission status: Runtime Error

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

M = []
x = 1
while x < (10 ** 5) * 2:
    M.append(1 / x)
    x <<= 1

p1 = max((N - K + 1) / N, 0)
p = 0
for i in range(1, min(N + 1, K)):
    t = int(math.log2(K / i)) + 1
    if K % i == 0 and  (K // i) & (K // i - 1) == 0:
        t -= 1
    p += M[t]
print(p / N + p1)

Submission status: Runtime Error

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

M = []
x = 1
while x < 10 ** 5:
    M.append(1 / x)
    x <<= 1

p1 = max((N - K + 1) / N, 0)
p = 0
for i in range(1, min(N + 1, K)):
    t = int(math.log2(K / i)) + 1
    if K % i == 0 and  (K // i) & (K // i - 1) == 0:
        t -= 1
    p += M[t]
print(p / N + p1)

Submission status: Runtime Error

Solution code:
fractions import Fraction
a, b = map(int, input().split())
ans = 0

for i in range(1, a+1):
  for j in range(10**6):
    if i*2**j > b:
      ans += Fraction(1, a*2**j)
      break

print(float(ans))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
import math
s=0
if N-K>=0:
  N-=(N-K+1)
for j in range(1,N+1):
  if (K/j)%2==0:
    s+=math.log2(K//j)
  else:
    s+=int(math.log2(K/j))+1
print(float(N/(s+N)))

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
import math
s=0
for j in range(1,N+1):
  if (K/j)%2==0:
    s+=math.log2(K//j)
  else:
    s+=int(math.log2(K/j))+1
print(float(N/(s+N)))

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
import math
s=0
for j in range(1,N+1):
  if (K/j)%2==0:
    s+=log2(K//j)
  else:
    s+=int(log2(K/j))+1
print(float(N/(s+N)))

Submission status: Runtime Error

Solution code:
import math

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

ans = 0
for val in range(1,n+1):
    #print(val,",",math.log2(k)-math.log2(val))
    x = math.ceil(math.log2(k)-math.log2(val))
    ans = ans + 1/n * (1/2)**x 
print(ans)

Submission status: Runtime Error

Solution code:
import math
N, K = [int(i) for i in input().split()]
n = []
k = K
res = 0
while k!=1:
    n.append(k)
    k = math.ceil(k/2)

for i in range(len(n)):
    if N >= n[i]:
        res += (N-n[i]+1)/2**i
        o = i
        break

while o < len(n) - 1:
    res += (n[o] - n [o + 1]) / 2 ** (o + 1)
    o += 1
 
res = res / N
print(res)

Submission status: Runtime Error

Solution code:
from functools import reduce
from operator import mul


def end_of_loop():
    raise StopIteration


def main():
    N, K = map(int, input().split())
    print(sum(reduce(mul, (0.5
                           if i << j < K
                           else end_of_loop()
                           for j in range(bin(K)-2)), 1 / N)
              for i in range(1, N + 1)))
    return


main()

Submission status: Runtime Error

Solution code:
import numpy as np

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

count = 0.

for i in range(1,num+1):
    if i <= k-1:
        times = np.log2(10/i)
        times = int(times) +1
        count += (1/num) * (1/2)**times
    elif i >= k:
        count += 1/num
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

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

count = 0

for i in range(1,num+1):
    if i <= k-1:
        times = np.log2(10/i)
        times = int(times) +1
        count += (1/num) * (1/2)**times
    elif i >= k:
        count += (1/num)
print(count)

Submission status: Runtime Error

Solution code:
import math

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

count = 0

for i in range(1,num+1):
    if i <= k-1:
        times = math.log2(10/i)
        times = int(times) +1
        count += (1/num) * (1/2)**times
    elif i >= k:
        count += (1/num)
print(count)

Submission status: Runtime Error

Solution code:
import math
N, K = [int(i) for i in input().split()]
n = [K]
k = K
while True:
    k /= 2
    n.append(math.ceil(k))
    if math.ceil(k)==1:break

n.reverse()
ma=[(1/2)**i for i in range(len(n))]
t=[]
m=len(n)
for i,(j,k) in enumerate(zip(n[1:],n)):
    t+=[ma[m-i-1]]*(j-k)
if N>K:t+=[1]*(N-K+1)
else: t=t[:N]
print("{:9f}".format(math.fsum(t)/len(t)))

Submission status: Runtime Error

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