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:
#!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(int(math.log2(k) + 1))]
    for num, i in enumerate(nibuiti):
        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[int(math.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:
import math
from math import ceil
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
    k=ceil(math.log2(K/i))
    k=max(0,k)
    ans+=(1/N)*(1/2)**k
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

m = 0
g = 0
ps = p
for i in range(n):
    g = i+1
    while g < k:
        g = g * 2
        m = m + 1
    p = double(0.5**m) / n 
    ps = ps + p

print(ps)

Submission status: Runtime Error

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

m = 0

while g < k:
    g = n * 2
    m = m + 1

double(p) = 0.5**m
print(p)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
N, K = list(map(int, input().split()))
result = 0
for i in range(1, N+1):
  result += (1/N) * 0.5 ** (math.floor(math.log(K//i, 2))+1)
print("{:.12}".format(result))

Submission status: Runtime Error

Solution code:
import numpy as np
 
N, K = map(int, input().split())
 
def get_x(n, K):
    if n >= K:
        return 0
    else:
      	x_raw = (np.log(K) - np.log(n))/np.log(2)
        # x_raw = np.log2(K) - np.log2(n)
        return np.ceil(x_raw)

def get_prob(n, K):
    x = get_x(n, K)
    if x == 0:
        return 1
    else:
        return (1/2)**x
    
ans = np.mean([get_prob(n, K) for n in range(1, N+1)])
 
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
import math
 
N, K = map(int, input().split())
 
 
prob = []
if N >= K:
    p_e = (1 / N) * (N - K + 1)
    for i in range(1, K):
        p_i = (1 / N) * ((1 / 2) ** (math.ceil((np.log2(K / i))))
        prob.append(p_i)
else:
    p_e = 0
    for i in range(1, N+1):
        p_i = (1 / N) * ((1 / 2) ** (math.ceil((np.log2(K / i))))
        prob.append(p_i)
 
summer = sum(prob) + p_e
 
print("{:.12f}".format(summer))

Submission status: Runtime Error

Solution code:

"""
Created on Sun May 19 14:10:21 2019

@author: taikinaka
"""
#print('put key')
K = int(input())
#print('Put numbers')
prob = 0
N = int(input())
for a in range(1,N+1):
    p = 0
    num = a
    while(K >num):
        num=num*2
        #print('num=',num)
        p = p + 1
    #print("p=",p)
    prob = prob + 0.5**p
prob = prob/N
print(prob)

Submission status: Runtime Error

Solution code:
'''input
100000 5
'''
from math import ceil, log2
N, K = [int(x) for x in input().split()]

ats = 0.0

for i in range(1, N+1):
	if i >= K:
		ats += 1/N
		continue

	ats += 1/N*2**(-ceil(log2(K/i)))

print(ats)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
if K > 10000:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
if K > 50000:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
if K > 5000:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
if N > 3500:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
if N > 4000:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
if N > 3000:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
if N > 5000:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
if N > 1000:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
if N > 10000:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
if K >= 100000:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
if N >= 100000:
  raise IndexError
cnt = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif math.log(K/n)%math.log(2)<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt += (0.5)**x
 
print(cnt/N)

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc126
# -*- coding: utf-8 -*-
import math

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

threshold = 1
counter = 0
while(threshold < k):
        counter += 1
        threshold *= 2

ans = 0
for i in range(n):
        if i+1 >= k:
                ans += 1 / n
        else:
                ans += 1 / (n * pow(2,counter))
        counter -= 1

print( ans )

Submission status: Runtime Error

Solution code:
import math
import sys
import numpy

N,K = int(input())
ans = 0.000000000
for i in range(1,N+1):
    if i >= K:
        ans += 1
    else :
        ans += math.log2(K/i)/2

ans /= N
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
 
n, k = map(int, input().split())
prob = 0
for i in range(1, n+1):
  count = 0
  total = i
  while total < k:
    total *= 2
    count += 1
  prob += 1/2**p
print(prob/n)

Submission status: Runtime Error

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

t = []
d = k
while(True):
  d = d / 2
  t.append(d)
  if d <= 1:
    break
# print(t)

t2 = []
nn = 1+n if n < k else k
for i in range(1, nn):
  for j in range(len(t)):
    if i >= t[j]:
      t2.append(j+1)
      break
# print(t2)

t3 = [0.5]
for i in range(1, math.ceil(math.log2(k))):
  t3.append(t3[i-1]*0.5)
# print(t3)

r = 0
for t in t2:
  r += t3[t-1]
r /= n
if n >= k:
  r += (n-k+1) / n
print(r)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
half=[K]
for i in range(1,K):
    if K%(2**i)==0:
        half.append(int(K/(2**i)))
    else:
        half.append(1+int(K/(2**i)))
    maxi=i
    if int(K/(2**i))==0:
        break
half.sort()

ans=[]
if half[0]<N:
   # ans.append(half[0]/(2**(maxi)))

    for i in range(maxi):

        
        if half[i+1]<N:
            sa=half[i+1]-half[i]
        #    print(half[i],sa)
            ans.append(sa/(2**(maxi-i)))
        else:
            sa=N-half[i]
      #      print(half[i],sa)
            ans.append(sa/(2**(maxi-i)))
            j=i
            break

if half[j+1]==N:
    #print(half[j+1])
    ans.append(1/(2**(maxi-j-1)))
            
if half[-1]<N:
    sa=N-half[-1]+1
  #  print(half[-1],sa,"kjh")
    ans.append(sa)



#print(half)
#print(ans)
ans=sum(ans)/N
print(ans)

Submission status: Runtime Error

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

t = []
d = k
while(True):
  d = d / 2
  t.append(d)
  if d <= 1:
    break
# print(t)

t2 = []
nn = 1+n if n < k else k
for i in range(1, nn):
  for j in range(len(t)):
    if i >= t[j]:
      t2.append(j+1)
      break
# print(t2)

t3 = [0.5]
for i in range(1, len(t2)+2):
  t3.append(t3[i-1]*0.5)
# print(t3)

r = 0
for t in t2:
  r += t3[t-1]
r /= n
if n >= k:
  r += (n-k+1) / n
print(r)

Submission status: Runtime Error

Solution code:
import math
import sys
import numpy

N,K = int(input())
ans = 0.000000000
for i in range(1,N+1):
    if i >= K:
        ans += 1
    else :
        ans += math.log(K/i,2)/2

ans /= N
print(ans)

Submission status: Runtime Error

Solution code:
from math import log2

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

ab = 0.0

if n <= k:

    for i in range(1,n+1):
        a = k//int(i)
        ex = int(math.log2(a) + 1
        ab = ab + (1.0/n)*(0.50**ex)

    print(ab)

else:

    for i in range(1,k):
        a = k//int(i)
        ex = int(math.log2(a) + 1
        ab = ab + (1.0/n)*(0.50**ex)
    
    ab = ab + float(n-k+1)/float(n)
    print(ab)

Submission status: Runtime Error

Solution code:
import math
import decimal
n = [int(e) for e in input().split()]
x=decimal.Decimal("0")
for i in range(1,n[0]+1):
  if(i<n[1]):
    y=decimal.Decimal(1/(2**(math.log2(b/i)//1+(1))))
    x=x+y
  else:
    x=x+1
print(x/n[0])

Submission status: Runtime Error

Solution code:
import math
import sys

N,K = int(input())
ans = 0.000000000
for i in range(1,N+1):
    tmp = i
    q = 1.0000000/N
    while(tmp < K):
        q /= 2.00000000
        tmp *= 2
print(ans*1.0000000000000000000)

Submission status: Runtime Error

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

import math
P = 0
if N < K:
for i in range(1,K):
    P += ((0.5)**(math.ceil( math.log2(float(K/i)) )))/N
else:
    P += (N-K)/N 
    for i in range(K,N+1):
        P += ((0.5)**(math.ceil( math.log2(float(K/i)) )))/N
print(P)

Submission status: Runtime Error

Solution code:
import math
n,k=map(int,input().split())
res=0
rt=math.ceil(math.sqrt(k))
for i in range(1,n+1):
    if i < k:
        res+=(1/n)*((1/2)**rt)
        rt-=1
    elif i == k or i>k:
        res+=1/n
print(res)

Submission status: Runtime Error

Solution code:
N,K = map(int,input()split())
a = 0
b = 0
c = []
if N < K:
  for i in range(1,N):
    while b < N:
      for k in range(N):
      	b = i*2**k
      	c.append(1)
    a = a + (1/N*0.5**int(len(c)))
elif N >= K:
  a = (N-K+1)/N
  for j in range(1,K):
    a = a + (1/N*0.5**(K-j))
print(a)

Submission status: Runtime Error

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

import math
P = 0
if N < K:
for i in range(1,K):
    P += ((0.5)**(math.ceil( math.log2(float(K/i)) )))/N
else:
    P += (N-K)/N 
    for i in range(K,N+1)
        P += ((0.5)**(math.ceil( math.log2(float(K/i)) )))/N
print(P)

Submission status: Runtime Error

Solution code:
from fractions import Fraction
def oo(x):
    res = 1
    for i in range(x-1):
        res = res *2 +1
    return res
def dicpro(dicn,dice,point):
    p = dice
    n = 0
    while p < point:
        p *= 2
        n+=1
    return dicn * 2**n
n,k = map(int,input().split())
l = []
res = 1
#print(oo(n))
#x = oo(n)
mama = dicpro(n,1,k)
print(mama)
old = 2
print(res,mama)
print(round(float(Fraction(oo(n),mama)),10))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

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

if N > K:
  prob_base = (N-K) / N
  prob = 0
  for i in range(1, N-K+1):
    x = math.ceil(np.log2(K/i))
    prob += (1/N) * (1/2)**x
  
  print(prob_base + prob)

else:
  for i in range(1, N+1):
    x = math.ceil(np.log2(K/i))
    prob += (1/N) * (1/2)**x
  
  print(prob)

Submission status: Runtime Error

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

for i in range(N):
    if 2**i > N:
        a = i-1
        b = N - 2**a
        break
for j in range(K):
    if 2**j > K:
        c = j-1
        d = K - 2**c
        break

if N <= K:
    print((2**(2*a-c+1)+2**(-c)+3*2**(a-c+1)*b)/3N)
else:
    print((2**(c+1)+2**(-c)+3*2*b)/3N + (N-K+1)/N)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
import math
a = 4 * (math.ceil(math.log(K,N)))

Submission status: Runtime Error

Solution code:
import math
import decimal
decimal.getcontext().prec = 11
n = [int(e) for e in input().split()]
x=decimal.Decimal("0")
for i in range(1,n[0]+1):
  if(i<n[1]):
    y=decimal.Decimal(1/(2**(math.log2(b/i)//1+(1))))
    x=x+y
  else:
    x=x+1
print(x/n[0])

Submission status: Runtime Error

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

for i in range(N):
    n = i + 1
    if n < k:
        Sum += pow(0.5, math.ceil(math.log(K/n, 2)))
    else:
        Sum += 1
Sum = Sum / N
print(Sum)

Submission status: Runtime Error

Solution code:
N,K=map(int, input().split())
p=20
count=0
for i in range(N):
  if i>=K:
    count+=1
  else:
    for j in range(20):
      if i*pow(j,2)>=K:
        ans+=pow(j,1/2)
        break
    
  
    
print(count/100+i/j*ans)

Submission status: Runtime Error

Solution code:
import math
range2 = 17
tables = list(map(lambda x: 2.0 ** (range2-x), range(range2+1)))

line = input()
N , K = list(map(int, line.split(' ')))
result = 0
for i in range(N):
    dice = i + 1.0
    if dice >= K:
        result += tables[0]
        continue
    val = math.ceil(math.log2(K / dice))
    result += tables[val]
finalResult = result / N / (2**17)
print('{:.12f}'.format(finalResult))

Submission status: Runtime Error

Solution code:

from math import *
from fractions import Fraction as F



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

ans=0

oye=int(ceil(log2(k)))

how=min(n,k)
f=max(0,n-how)

dd=F((2**how)-1,(2**oye)*n)

sa=F(f,n)

dd+=sa

print ("{0:.10f}".format(dd.numerator/dd.denominator))

Submission status: Runtime Error

Solution code:
import math
N,K = map(int, input().split())
#出た目をｎとすると、n>=K以上が最初に出れば勝ち
#1からK-1のときで負ける確率を考える
ans=0
S=[]
for i in range(1,K):
  x = math.log(K/i,2)
  for j in range(17):
    if j >= x:
      S.append(j)
    ans+=1-(1/2)**S[0]
 
win_rate = 1-ans
print(win_rate)

Submission status: Runtime Error

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

probability = 0
X = 1
cnt = 0
while True:
    X *= 2
    cnt += 1
    if X >= K:
        break

for i in range(1, K+1):
    probability += 1/2**cnt
    cnt -= 1

print((probability + N - K) / N)

Submission status: Runtime Error

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

if N<K:
    pro = 0
    for n in range(N):
        if K % (2*(n+1))==0:
            X=K / (2*(n+1))-1
        else:
            X= K // (2*(n+1))+1
        pro += float(1/N/2**X)

    print(pro)

else:
    pro = (N-K+1)/N
    for n in range(K-1):
        if K % (2*(n+1))==0:
            X=K / (2*(n+1))-1
        else:
            X= K // (2*(n+1))+1

        pro += float(1/N/2**X)

    print(pro)

Submission status: Runtime Error

Solution code:
import math
from decimal import *
range2 = 17
tables = list(map(lambda x: 2.0 ** (range2-x), range(range2+1)))

line = input()
N , K = list(map(int, line.split(' ')))
result = 0
for i in range(N):
    dice = i + 1.0
    if dice >= K:
        result += tables[0]
        continue
    val = math.ceil(math.log2(K / dice))
    result += tables[val]
finalResult = Decimal(result) / Decimal(N) / Decimal(2**17)
print('{:.12f}'.format(finalResult))

Submission status: Runtime Error

Solution code:
import math
import decimal
decimal.getcontext().prec = 10
n = [int(e) for e in input().split()]
x=decimal.Decimal("0")
for i in range(1,n[0]+1):
  if(i<n[1]):
    y=decimal.Decimal(1/(2**(math.log2(b/i)//1+(1))))
    x=x+y
  else:
    x=x+1
print(x/n[0])

Submission status: Runtime Error

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


def createBorder(K):
    list_ = [K]
    k = K
    while k != 1:
        k = math.ceil(k / 2)
        list_.append(k)
    return list_

border = createBorder(K)
border.reverse()
max_pow_num = len(border)

i = 0
ans = 0
for n in range(1, N+1):
    ans += (1/N) * (1/2)**(max_pow_num-(i+1))
    try:
        if n == border[0]:
            i = border.pop(0)
    except:
        pass
print(ans)

Submission status: Runtime Error

Solution code:
l= list(map(int, input().split()))
N=l[0]
K=l[1]
ans=0
for n in range(1, N+1):
	cnt=0
    m=n
    while(m<K):
        m=m*2
        cnt+=1
    tmp=(2**(-cnt))/N
    ans+=tmp
print(ans)

Submission status: Runtime Error

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

t = []
d = k
while(True):
  d = d / 2
  t.append(d)
  if d <= 1:
    break
# print(t)

t2 = []
nn = 1+n if n < k else n-k
for i in range(1, nn):
  for j in range(len(t)):
    if i >= t[j]:
      t2.append(j+1)
      break
# print(t2)

t3 = [0.5]
for i in range(1, len(t2)+2):
  t3.append(t3[i-1]*0.5)
# print(t3)

r = 0
for t in t2:
  r += t3[t-1]
r /= n
if n >= k:
  r += k / n
print(r)

Submission status: Runtime Error

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

if N<K:
    pro = 0
    for n in range(N):
        if K % (2*(n+1))==0:
            X=K / (2*(n+1))-1
        else:
            X= K // (2*(n+1))+1
        pro += 1/N/2**X

    print(pro)

else:
    pro = (N-K+1)/N
    for n in range(K-1):
        if K % (2*(n+1))==0:
            X=K / (2*(n+1))-1
        else:
            X= K // (2*(n+1))+1
            
        pro += 1/N/2**X

    print(pro)

Submission status: Runtime Error

Solution code:

from math import *
from fractions import Fraction as F



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

ans=0

oye=int(ceil(log2(k)))

how=min(n,k)
f=max(0,n-how)

dd=F((2**how)-1,(2**oye)*n)

sa=F(f,n)

dd+=sa

print ("{0:.20f}".format(dd.numerator/dd.denominator))

Submission status: Runtime Error

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

r = 0
X = 1
while True:
  if X >= K:
    break
  X *= 2
  r += 1

a = 1 / N
result = 0

c = min(N, K)
for i in range(c):
  s = a*((1/2)**(r-i))
  result += s

if N > K:
  for i in range(N-(c+1)):
    result += a

print(result)

Submission status: Runtime Error

Solution code:
l= list(map(int, input().split()))
N=l[0]
K=l[1]
ans=0
for n in range(1, N):
	cnt=0
    m=n
    while(m<K):
        m*=2
        cnt+=1
    tmp=2**(-cnt)/N
    ans+=tmp
print(ans)

Submission status: Runtime Error

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

ans = 0.
k = K
k_list = []
watta_count = 0
for _ in range(17):
  k = k/2
  if k <= 0.5:
    break
  elif k <= N:
    k_list.append(math.ceil(k))
  watta_count += 1
k_list.reverse()
for i in range(len(k_list)-1):
    now = k_list[i]
    nex = k_list[i+1]
    cot = nex-now
    ans += (1/N)*((1/2)**watta_count) * cot
    watta_count -= 1
aa = N-k_list[-1]+1
ans += (1/N)*((1/2)**watta_count) * aa

print(ans)

Submission status: Runtime Error

Solution code:
a=input().split()
N=int(a[0])
K=int(a[1])
count=0
n=1
while True:
    count=count+0.5**math.ceil(math.log2(K)-math.log2(n))/n
    n=n+1
    if n==N:
        break
print(count)

Submission status: Runtime Error

Solution code:
s=input()
if 10*int(s[0])+int(s[1])<=12 and int(s[0])+int(s[1])!=0:
  if 10*int(s[2])+int(s[3])<=12 and int(s[2])+int(s[3])!=0:
    print("AMBIGUOUS")
  else:
    print("MMYY")
if 10*int(s[0])+int(s[1])>=13 or int(s[0])+int(s[1])==0:
  if 10*int(s[2])+int(s[3])<=12 and int(s[2])+int(s[3])!=0:
    print("YYMM")
  else:
    print("NA")

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
i=0
p=0
u=0
sum_a=0
number=[]
if N>=K:
    num = K-1
else:
    num = N
for a in range(1,num+1):
    sum_a=a
    while u<=1:
        sum_a1=sum_a*2
        sum_a =+sum_a1
        #print(sum_a)
        i=i+1
        #print(sum_a)
        if (sum_a)>=K:
            u=2
    number.append(i)
    u=0
    i=0
    sum_a1=0
if num!=N:
    for i in range(N-K):
        number.append(0)
for i in range(N):
    if number[i]!=0:
        a=(1/2)**int(number[i])
        #print(a)
        p = p +((1/N)*a)
        #print(p)
    else:
        p=p + (1/N)
    

print(p)

Submission status: Runtime Error

Solution code:
from decimal import Decimal

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

d = Decimal(1/(N))

tmp = 1
count = 0
while tmp <= K:
	tmp = tmp*2
	count += 1

ans += d*Decimal(0.5**count)

if N > K:
	for j in range(K-1):
		count -= 1
		ans += d*Decimal(0.5**count)

	ans = 1 - ans
else:
	for i in range(N-1):
		count -= 1
		ans += d*Decimal(0.5**count)

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
 
a,b=map(int, input().split())
 
probablity = 0.0
 
for i in range(a + 1):
  ceil = math.ceil(math.log2(b / (i + 1)))
  if(ceil < 0):
    ceil = 0
  elif(ceil < 1):
    ceil = 1
    
  probablity = probablity + 1 / (a * 2 ** ceil)
  
print(probablity)
import sys
import math
 
a,b=map(int, input().split())
 
probablity = 0.0
 
for i in range(a + 1):
  ceil = math.ceil(math.log2(b / (i + 1)))
  if(ceil < 0):
    ceil = 0
  elif(ceil < 1):
    ceil = 1
    
  probablity = probablity + 1 / (a * 2 ** ceil)
  
print(probablity)
import sys
import math
 
a,b=map(int, input().split())
 
probablity = 0.0
 
for i in range(a + 1):
  ceil = math.ceil(math.log2(b / (i + 1)))
  if(ceil < 0):
    ceil = 0
  elif(ceil < 1):
    ceil = 1
    
  probablity = probablity + 1 / (a * 2 ** ceil)
  
print(probablity)
import sys
import math
 
a,b=map(int, input().split())
 
probablity = 0.0
 
for i in range(a + 1):
  ceil = math.ceil(math.log2(b / (i + 1)))
  if(ceil < 0):
    ceil = 0
    
  probablity = probablity + 1 / (a * 2 ** ceil)
  
print(probablity)

Submission status: Runtime Error

Solution code:
a=input()
N=int(a.split()[0])
K=int(a.split()[1])
n=N
sum=0
for i in range(1,N):
  n=i
  count=0
  while(n<=K):
    count+=1
    n*=2
  c=float(1/N)
  d=float((1/2)^count)
  sum+=c*d
print(sum)

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
X_list =[]
if N<K:
    pro = 0.0
    for n in range(N):
        if K % (2*(n+1))==0:
            X_list.append(K / (2*(n+1))-1)
        else:
            X_list.append(K // (2*(n+1))+1)
    X_max = max(X_list)
    for _ in range(len(X_list)):
        X_list[_] =X_max-X_list[_]
        X_list[_] =2**X_list[_]

    pro += sum(X_list)/(N*2**X_max)

    print(pro)

else:
    pro = float((N-K+1)/N)

    for n in range(K-1):
        if K % (2*(n+1))==0:
            X_list.append( K / (2*(n+1))-1)
        else:
            X_list.append( K // (2*(n+1))+1)

    X_max = max(X_list)
    for _ in range(len(X_list)):
        X_list[_] = X_max - X_list[_]
        X_list[_] = 2 ** X_list[_]
    pro += sum(X_list)/(N*2**X_max)

    print(pro)

Submission status: Runtime Error

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

t = []
d = k
while(True):
  d = d / 2
  t.append(d)
  if d <= 1:
    break
# print(t)

t2 = []
for i in range(1, 1+n):
  for j in range(len(t)):
    if i >= t[j]:
      t2.append(j+1)
      break
# print(t2)

t3 = [0.5]
for i in range(1, len(t2)+2):
  t3.append(t3[i-1]*0.5)
# print(t3)

r = 0
for t in t2:
  r += t3[t-1]
print(r/n)

Submission status: Runtime Error

Solution code:
N = int(input().strip())
x = [[] for x in range(N)]
for i in range(N-1):
     u, v, w = list(map(int, input().split()))
     x[u-1].append([v-1, w])
     x[v-1].append([u-1,w])



ret = {}
done = []

queue = [0]

for i in range(N):
    curr = queue.pop()
    if curr == 0:
        ret[0] = 0

    for neigh in x[curr]:
        if neigh in done:
            continue
        if neigh[1] % 2 == 0:
            ret[neigh[0]] = ret[curr]
        else:
            ret[neigh[0]] = 0 if ret[curr] == 1 else 1

        queue.append(neigh[0])
    done.append(curr)


for i in range(N):
    print(ret[i])

Submission status: Runtime Error

Solution code:
import sys
import math
 
a,b=map(int, input().split())
 
probablity = 0.0
 
for i in range(a + 1):
  ceil = math.ceil(math.log2(b / (i + 1)))
  if(ceil < 0):
    ceil = 0
  elif(ceil < 1):
    ceil = 1
    
  probablity = probablity + 1 / (a * 2 ** ceil)
  
print(probablity)
import sys
import math
 
a,b=map(int, input().split())
 
probablity = 0.0
 
for i in range(a + 1):
  ceil = math.ceil(math.log2(b / (i + 1)))
  if(ceil < 0):
    ceil = 0
  elif(ceil < 1):
    ceil = 1
    
  probablity = probablity + 1 / (a * 2 ** ceil)
  
print(probablity)

Submission status: Runtime Error

Solution code:
import math
n = [int(e) for e in input().split()]
x=decimal.Decimal(0)
for i in range(1,n[0]+1):
  if(i<n[1]):
    x=x+1/(2**(math.log2(n[1]/i)//1+1))
  else:
    x=x+1.
print(x/n[0])

Submission status: Runtime Error

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

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

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

print(kakus)

Submission status: Runtime Error

Solution code:
import math
def sol(inp=input):
    n,k=map(int,inp().split())
    res=0
    for dice_m1 in range(n):
        dice=dice_m1+1
        head=max(0,math.ceil(math.log2(k/dice)))
        res+=2**-head
    res/=n
    return res
print(sol())

Submission status: Runtime Error

Solution code:
input = sys.stdin.readline
def C():
    N, K = input().split()
    N = int(N)
    K = int(K)
    n = [i for i in range(1, N+1)]
    x2 = [2**i for i in range(20)]
    k = [K /n[i-1] for i in range(1, N+1)]
    #print(k)
    #print(x2)
    #print(len(n))
    #print(n[0])
    #print(len(k))
    c = []
    for x in n:
        for i in x2:
            if k[x-1] < i:
                print('k:{}'.format(k[x-1]))
                print('i:{}'.format(i))
                c.append(x2.index(i))
                break
    cc = [pow(0.5, i) for i in c]
    print(1 / N * sum(cc))
            
if __name__ == '__main__':
    C()

Submission status: Runtime Error

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

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

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

#prob_list = list(map(calc_prob,m_list))

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