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: Wrong Answer

Solution code:
n,k=map(int,input().split())
if k==1:
  print(1)
  exit()
e=[0]*(k)
e[-2]=1
now=k
while int(now)!=1:
  if now%2==0 and int(now)!=2:
    now=now/2
    e[int(now)-2]+=1
  elif int(now)==2:
    now+=-1
    e[int(now)-1]+=1
  else:
    now=now/2
    e[int(now)-1]+=1
e_=[]
for i in range(k):
  if i==0:
    e_.append(e[k-1-i])
  else:
    e_.append(e[k-1-i]+e_[-1])       
ans=0    
if n<k:
  for i in range(n):
    t=1
    for _ in range(e_[k-1-i]):
      t/=2
    ans+=t  
  print(ans/n) 
else:
  for i in range(k):
    t=1
    for _ in range(e_[k-1-i]):
      t/=2  
    ans+=t  
  ans=ans*(1/n)
  ans+=(n-k)*(1/n)
  print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if k==1:
  print(1)
  exit()
e=[0]*(k)
e[-2]=1
now=k
while now!=1:
  if now%2==0 and now!=2:
    now=now//2
    e[now-2]+=1
  elif now==2:
    now+=-1
    e[now-1]+=1
  else:
    now=now//2
    e[now-1]+=1
e_=[]
for i in range(k):
  if i==0:
    e_.append(e[k-1-i])
  else:
    e_.append(e[k-1-i]+e_[-1])       
ans=0    
if n<k:
  for i in range(n):
    t=1
    for _ in range(e_[k-1-i]):
      t/=2
    ans+=t  
  print(ans/n) 
else:
  for i in range(k):
    t=1
    for _ in range(e_[k-1-i]):
      t/=2  
    ans+=t  
  ans=ans*(1/n)
  ans+=(n-k)*(1/n)
  print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if k==1:
  print(1)
  exit()
e=[0]*(k)
e[-2]=1
now=k
while now!=1:
  if now%2==0 and now!=2:
    now=now//2
    e[now-2]+=1
  elif now==2:
    now+=-1
    e[now-1]+=1
  else:
    now=now//2
    e[now-1]+=1
e_=[]
for i in range(k):
  if i==0:
    e_.append(e[k-1-i])
  else:
    e_.append(e[k-1-i]+e_[-1])   
ans=0    
if n<k:
  for i in range(n):
    t=1
    for _ in range(e_[k-1-i]):
      t/=2
    ans+=t  
  print(ans/n) 
else:
  for i in range(k):
    t=1
    for _ in range(e[k-1-i]):
      t/=2
    ans+=t  
  ans=ans/n
  ans+=(n-k)/n
  print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if k==1:
  print(1)
  exit()
e=[0]*(k)
e[-2]=1
now=k
while now!=1:
  if now%2==0 and now!=2:
    now=now//2
    e[now-2]+=1
  elif now==2:
    now+=-1
    e[now-1]+=1
  else:
    now=now//2
    e[now-1]+=1
e_=[]
for i in range(k):
  if i==0:
    e_.append(e[k-1-i])
  else:
    e_.append(e[k-1-i]+e_[-1])   
ans=0    
if n<k:
  for i in range(n):
    ans+=(0.5)**e_[k-1-i]
  print(ans*(1/n))  
else:
  for i in range(k):
    ans+=((0.5)**e_[k-1-i])
  ans=ans*(1/n)  
  ans+=(1/n)*(n-k)
  print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if k==1:
  print(1)
  exit()
e=[0]*(k)
e[-2]=1
now=k
while now!=1:
  if now%2==0 and now!=2:
    now=now//2
    e[now-2]+=1
  elif now==2:
    now+=-1
    e[now-1]+=1
  else:
    now=now//2
    e[now-1]+=1
e_=[]
for i in range(k):
  if i==0:
    e_.append(e[k-1-i])
  else:
    e_.append(e[k-1-i]+e_[-1])   
ans=0    
if n<k:
  for i in range(n):
    ans+=(1/2)**e_[k-1-i]
  print(ans*(1/n))  
else:
  for i in range(k):
    ans+=((1/2)**e_[k-1-i])
  ans=ans*(1/n)  
  ans+=(1/n)*(n-k)
  print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if k==1:
  print(1)
  exit()
e=[0]*(k)
e[-2]=1
now=k
while now!=1:
  if now%2==0 and now!=2:
    now=now//2
    e[now-2]+=1
  elif now==2:
    now+=-1
    e[now-1]+=1
  else:
    now=now//2
    e[now-1]+=1
e_=[]
for i in range(k):
  if i==0:
    e_.append(e[k-1-i])
  else:
    e_.append(e[k-1-i]+e_[-1])   
ans=0    
if n<k:
  for i in range(n):
    ans+=((1/2)**e_[k-1-i])*(1/n)
  print(ans)  
else:
  for i in range(k):
    ans+=((1/2)**e_[k-1-i])*(1/n)
  ans+=(1/n)*(n-k)
  print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 12, 2020 15:02:31 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


import bisect
from sys import stdin
input = stdin.readline


def least(n, k):
  return bisect.bisect_left(list(map(lambda x: n*2**x, range(20))), k)


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

  P = 0
  for i in range(1, N+1):
    if 0 < i < K:
      P += (1/N) * (0.5)**least(i, K)
      print(P)
    if K <= i:
      P += (1/N)
      print(P)

  print(P)


if(__name__ == '__main__'):
  main()

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
import math

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    n, k = mi()
    nr = 1/n
    rate = 0.5

    ans = 0
    if n >= k:
        ans += (n - k + 1) * nr
        n = k - 1
    left, right = k//2, k
    while right > 0:
        if left <= n:
            cnt = n - left
            ans += cnt * nr * rate
            n = left
        rate /= 2
        left, right = left//2, left
        
    print(f"{ans:.12f}")
    return

main()

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
import math

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    n, k = mi()
    nr = 1/n
    rate = 0.5

    ans = 0
    if n > k:
        ans += (n - k + 1) * nr
        n = k - 1
    left, right = k//2, k
    while right > 0:
        if left <= n:
            cnt = n - left
            ans += cnt * nr * rate
            n = left
        rate /= 2
        left, right = left//2, left
        
    print(f"{ans:.12f}")
    return

main()

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
import math

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    n, k = mi()
    nr = 1/n
    rate = 0.5

    ans = 0
    if n > k:
        ans += (n - k + 1) * nr
        n = k - 1
    left, right = k//2, k
    while right > 0:
        if left <= n:
            cnt = n - left
            ans += cnt * nr * rate
            n = left
        rate /= 20
        left, right = left//2, left
        
    print(f"{ans:.10f}")
    return

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
total=0
for i in range(1,N+1):
    for j in range(20):
        if (2**j)*i<K<=(2**(j+1))*i:
            a=j+1
            total+=(1/2)**a
            break

print((1/N)*total)

Submission status: Wrong Answer

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

for i in range(1, N + 1):
    tmp = 1 / 3
    now = i
    while now < K:
        tmp *= 0.5
        now *= 2
    ans += tmp
    
print(ans)

Submission status: Wrong Answer

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

for i in range(1, N + 1):
    tmp = 1 / N
    now = i
    while now <= K:
        now *= 2
        tmp /= 2
    
    ans += tmp
        
print(ans)

Submission status: Wrong Answer

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

for i in range(1, N + 1):
    tmp = 1 / N
    now = i
    while now <= K:
        now *= 2
        tmp *= 1 / 2
    
    ans += tmp
        
print(ans)

Submission status: Wrong Answer

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

import math
ans = 0
for i in range(1,n+1):
  if i < k:
    t = int(k/(2*i))
    if t == int(t):
      ans += 1/(2**(t+1))
    else:
      ans += 1/(2**t)
  else:
    ans += 1
  
print(ans/n)

Submission status: Wrong Answer

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

import math
ans = 0
for i in range(1,n+1):
  if 1 < i < k:
    t = int(k/(2*i))
    if t == int(t):
      ans += 1/(2**(t+1))
    else:
      ans += 1/(2**t)
  elif i == 1:
    t = math.sqrt(k)
    if t != int(t):
      ans += 1/(2**int(t+1))
    else:
      ans += 1/(2**t)
  else:
    ans += 1
  
print(ans/n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=(int(x) for x in input().split())
total=0
j=0
count=0
while k>(2**j):
    j=j+1
for i in range(j,1,-1):
    pro=(1/n)*((1/2)**i)
    total=total+pro
    count=count+1
while(count<n-1):
    total=total+1/n
    count=count+1
print(round(total,12))

Submission status: Wrong Answer

Solution code:
n,k=(int(x) for x in input().split())
total=0
j=0
count=0
while k>(2**j):
    j=j+1
for i in range(j,1,-1):
    pro=(1/n)*((1/2)**i)
    total=total+pro
    count=count+1
while(count!=n-1):
    total=total+1/n
    count=count+1
print(round(total,12))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
nums = []
ans = 0
for i in range(1, n+1):
    temp = i
    counter = 0
    while k > temp:
        temp *= 2
        counter += 1

    ans += 1/n * (1/2)**counter
    print(counter)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=(int(x) for x in input().split())
total=0
j=0
count=0
while k>(2**j):
    j=j+1
for i in range(j,1,-1):
    pro=(1/n)*((1/2)**i)
    total=total+pro
    count=count+1
while(count!=n-1):
    total=total+1/n
    count=count+1
print(round(total,12))

Submission status: Wrong Answer

Solution code:
n,k=(int(x) for x in input().split())
total=0
j=0
count=0
while k>(2**j):
    j=j+1
for i in range(j,1,-1):
    pro=(1/n)*((1/2)**i)
    total=total+pro
    count=count+1
while(count!=n):
    total=total+1/n
    count=count+1
print(round(total,12))

Submission status: Wrong Answer

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

qs = 0
for i in range(1, N+1):
    if i > K:
        qs += 1/N
    elif i <= K:
        q = 1/N
        while i <= K:
            q *= 1/2
            i *= 2
        qs += q
print(qs)

Submission status: Wrong Answer

Solution code:
import math

def fl(x):
    digits = 11
    form = '%.'+str(digits-1)+'e'
    return float((form % x))

N,K = map(int,input().split())
p = [0] * (N+1)
for i in range(1,N+1):
    if (1 <= i) and (i <= K-1):
        r = int(1+math.log(K/i,2))
        p[i] = fl( (1/N) * math.pow(1/2,r) )
    elif i >= K:
        p[i] = fl(1/N)
ans = sum(p)
print(fl(ans))

Submission status: Wrong Answer

Solution code:
import math

def fl(x):
    digits = 10
    form = '%.'+str(digits-1)+'e'
    return float((form % x))

N,K = map(int,input().split())
p = [0] * (N+1)
for i in range(1,N+1):
    if (1 <= i) and (i <= K-1):
        r = int(1+math.log(K/i,2))
        p[i] = fl( (1/N) * math.pow(1/2,r) )
    elif i >= K:
        p[i] = fl(1/N)
ans = sum(p)
print(fl(ans))

Submission status: Wrong Answer

Solution code:
import math

N,K = map(int,input().split())
p = [0] * (N+1)
for i in range(1,N+1):
    if (1 <= i) and (i <= K-1):
        r = int(1+math.log(K/i,2))
        p[i] = float( (1/N) * (math.pow(1/2,r)) )
    elif i >= K:
        p[i] = float(1/N)
ans = sum(p)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N,K = map(int,input().split())
p = [0] * (N+1)
for i in range(1,N+1):
    if (1 <= i) and (i <= K-1):
        r = int(1+math.log(K/i,2))
        p[i] = math.pow(1/2,r)
    elif i >= K:
        p[i] = 1
ans = sum(p) / N
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N,K = map(int,input().split())
p = [0] * (N+1)
for i in range(1,N+1):
    if (1 <= i) and (i <= K-1):
        r = int(1+math.log(K/i,2))
        p[i] = (1/N) * math.pow(1/2,r)
    elif i >= K:
        p[i] = 1/N
ans = sum(p)
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
border = []
inx = 0
while K > 1:
  border.append(K)
  K = (K + 1) >> 1
  inx += 1
border.append(1)
border.reverse()
pre = 1
cnt = []
for i in range(1, len(border)):
  if N < border[i]:
    cnt.append(N - pre)
    break
  elif N == border[i]:
    cnt.append(border[i] - pre)
    cnt.append(1)
    break
  else:
    cnt.append(border[i] - pre)
    pre = border[i]
if N >= border[-1]:
  cnt.append(N - border[-1] + 1)
ans = 0
for c in cnt:
  ans += c * 0.5 ** inx
  inx -= 1
print(ans/N)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
border = []
inx = 0
while K > 1:
  border.append(K)
  K = (K + 1) >> 1
  inx += 1
border.append(1)
border.reverse()
pre = 1
cnt = []
for i in range(1, len(border)):
  if N < border[i]:
    cnt.append(border[i] - pre)
    break
  elif N == border[i]:
    cnt.append(border[i] - pre)
    cnt.append(1)
    break
  else:
    cnt.append(border[i] - pre)
    pre = border[i]
if N >= border[-1]:
  cnt.append(N - border[-1] + 1)
ans = 0
for c in cnt:
  ans += c * 0.5 ** inx
  inx -= 1
print(ans/N)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
border = []
inx = 0
while K > 1:
  border.append(K)
  K = (K + 1) >> 1
  inx += 1
border.append(1)
border.reverse()
pre = 1
cnt = []
for i in range(1, len(border)):
  if N < border[i]:
    cnt.append(border[i] - pre)
    break
  elif N == border[i]:
    cnt.append(border[i] - pre)
    cnt.append(1)
    break
  else:
    cnt.append(border[i] - pre)
    pre = border[i]
if N > border[-1]:
  cnt.append(N - border[-1] + 1)
ans = 0
for c in cnt:
  ans += c * 0.5 ** inx
  inx -= 1
print(ans/N)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
p=0
for i in range(1,n+1):
  if i<k: p+=4*0.5**len(bin(k//i))
  else: p+=1
print(p/n)

Submission status: Wrong Answer

Solution code:
import math
n, k = [int(v) for v in input().split()]
rate = []
for i in range(1, n + 1):
    if i >= k:
        rate.append(1)
        continue

    coin = int(math.log2(k / i)) + 1
    rate.append(1 / (2 ** coin))

print(sum(rate) / len(rate))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
for i in range(1,n+1):
  if i >= k: continue
  t = 0
  while i < k:
    i *= 2
    t += 1
  else:
    ans += 0.5**t/n
  
print(ans)

Submission status: Wrong Answer

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

rate = 0

import math

for dice in range(1,N+1):
    #まず dice点
    cnt = math.ceil(math.log2(K/dice))
    rate += pow(1/2,cnt)

print(rate/N)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


def zz():
    return list(map(int, input().split()))


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


N, K = zz()
# if(N >= K):
#     ans = (N-K+1)/N
# else:
#     ans = 0
ans = 0.0
for n in range(1, N+1):
    x = max(int(np.log2(K/n))+1, 0)
    # print('n=', n, 'x=', x)
    tmp = 1/N * pow(1/2, x)
    ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


def zz():
    return list(map(int, input().split()))


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


N, K = zz()
if(N >= K):
    ans = (N-K+1)/N
else:
    ans = 0
for n in range(1, min(K, N+1)):
    x = max(int(np.log2(K/n))+1, 0)
    # print('n=', n, 'x=', x)
    tmp = 1/N * pow(1/2, x)
    ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
dk = [1,k,float("inf")]
ans = 0

while k > 2:
    k /= 2
    dk.append(int(-(-k//1)))
    
dk = sorted(dk)[::-1]
    
for i in range(len(dk)-1):
    num = min(dk[i],n) - dk[i+1] + 1*(min(dk[i],n)==dk[i+1])
    
    if num < 1:
        num = 0
        
    ans += num/n * (0.5**i)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

    x = math.ceil(math.log(K/i,2))
    print(x)
    ans += (0.5 ** x) / N

print(ans)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
N, K = map(int, input().split())
t = 0
i = 1
while(i < K):
    t += 1
    i *= 2
under = 2**t

p = 0
for i in range(1, N+1):
    c = 0
    while(i < K):
        c += 1
        i *= 2
    p += 2**(t-c)
print(p)
print(Decimal(p/((2**t)*N)))

Submission status: Wrong Answer

Solution code:
N,K  = map(int, input().split()) 
POINT = [0]*N
OK = [False]*N
Pro = [0]*17
for i in range(N):
    POINT[i] = i+1


for i in range(len(Pro)):
    for j in range(N):
        if OK[j] == False:
            if POINT[j]>=K:
                OK[j] = True
                Pro[i] += 1
            POINT[j] *=2

ans = 0
for i in range(len(Pro)):
    ans +=  Pro[i]/(2**i)

print(ans/N)

Submission status: Wrong Answer

Solution code:
N,K  = map(int, input().split()) 
POINT = [0]*N
OK = [False]*N
Pro = [0]*15
for i in range(N):
    POINT[i] = i+1


for i in range(len(Pro)):
    for j in range(N):
        if OK[j] == False:
            if POINT[j]>=K:
                OK[j] = True
                Pro[i] += 1
            POINT[j] *=2

ans = 0
for i in range(len(Pro)):
    ans +=  Pro[i]/(2**i)

print(ans/N)

Submission status: Wrong Answer

Solution code:
N,K  = map(int, input().split()) 
POINT = [0]*N
OK = [False]*N
Pro = [0]*14
for i in range(N):
    POINT[i] = i+1


for i in range(len(Pro)):
    for j in range(N):
        if OK[j] == False:
            if POINT[j]>=K:
                OK[j] = True
                Pro[i] += 1
            POINT[j] *=2

ans = 0
for i in range(len(Pro)):
    ans +=  Pro[i]/(2**i)

print(ans/N)

Submission status: Wrong Answer

Solution code:
import math

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

ans=0
for i in range(N):
    ans+=1/N*0.5**(math.ceil(math.log(K/(i+1),2)))
print(ans)

Submission status: Wrong Answer

Solution code:
from math import log

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

ans = 0

for i in range(n):
    if (i+1)<k:
        ans += (1/n) * 0.5**((log(k/(i+1), 2)//1)+1)
    else:
        ans += (1/n)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(1,n+1):
    if i >= k:
        ans += 1
    else:
        m = int(math.log2(k/i)) + 1 # 必要な回数
        ans += 0.5**m
print(ans / n)

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(1,n+1):
    if i >= k:
        ans += 1
    else:
        m = int(math.log2(k/i)) + 1 # 必要な回数
        print(i, m)
        ans += 0.5**m
        print(0.5**m / n)
print(ans / n)

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(1,n+1):
    if i >= k:
        ans += 1 / n
    else:
        m = int(math.log2(k/i)) + 1 # 必要な回数
        ans += 0.5**m / n
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
ans_list = list()
for i in range(1, N+1):
  index = 0
  count = 0
  while i*(2**index) < K:
    index += 1
    count += 1
  ans_list.append(count)
print(ans_list)  
ans = list(map(lambda x:0.5**x,ans_list))


print(sum(ans)/N)

Submission status: Wrong Answer

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

ans = 0
for i in range(n):
    tmp = 1 / n
    score = i + 1
    while score < 10:
        score *= 2
        tmp /= 2
    ans += tmp

print (ans)

Submission status: Wrong Answer

Solution code:
def getCount(a, b):
	count = 0
	while(True):
		if a < b:
			a = a*2
			count += 1
		else:
			return count

  
def answer(n, k):
    posibility = 0
    if (n >= k):
        posibility = 1/n * (n-k+1)
        print(posibility)
        for i in range(1, k):
            posibility += ((1)/(n))*((1/2)**(getCount(i, k)))
    else:
        for i in range(1, n+1):
            count = (getCount(i, k))
            posibility += 1/n*((1/2)**(getCount(i, k)))
    return posibility
        
n, k = map(int, input().split())
print(answer(n, k))

Submission status: Wrong Answer

Solution code:
import math

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

ans = (1 / n) * (1 / 2)**math.floor(math.log(k, 2) + 1)

for i in range(2, n + 1):
    d = math.floor(math.log(k, i))
    ans += (1 / n) * (1 / 2)**d

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int, input().split())
n = 1
while K > 2**n:
  n += 1
ans = 0.5**n
pre = 1
for i in range(n - 1, -1, -1):
  k = ceil(K / (2**i))
  if N >= k:
    ans += (k - pre) * (0.5 ** i)
    if N == k:
      break
  else:
    ans += (N - pre) * (0.5 ** i)
    break
  pre = k
if N > K:
  ans += N - K
print(ans / N)

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int, input().split())
n = 1
while K > 2**n:
  n += 1
ans = (1 / N) * (0.5**n)
pre = 1
for i in range(n - 1, -1, -1):
  k = ceil(K / (2**i))
  if N >= k:
    ans += (1 / N) * (k - pre) * (0.5 ** i)
    if N == k:
      break
  else:
    ans += (1 / N) * (N - pre) * (0.5 ** i)
    break
  pre = k
if N > K:
  ans += (1 / N) * (N - K)
print(ans)

Submission status: Wrong Answer

Solution code:

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

sum = 0
for i in range(N):
    X = math.log2(K/(i+1))
    X = math.floor(X) if X % 1 == 0 else math.floor(X+1)
    #print(X)
    sum += (1/N)*(1/2)**X
    
print(sum)

Submission status: Wrong Answer

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

ans = max(N-K+1, 0) / N
i = 1
top = min(N, K-1)
while True:
    under = K // 2**i
    
    if under >= N:
        i += 1
        continue
    ans += (0.5**i / N) * (top - under)
    i += 1
    top = under
    
    if top == 0: break

print(ans)

Submission status: Wrong Answer

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

def count(k,i):
    cnt=0
    while k>i:
        k//=2
        cnt+=1
    return cnt

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

Submission status: Wrong Answer

Solution code:
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from fractions import gcd
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (
    acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians,
    sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


n, k = invr()
res = 0
l = min(n, k)
for i in range(1, n+1):
    if i >= (k-1):
        res += (1/n)
    else:
        x = int(ceil(log2((k)/i)))
        res += (1/n) * (1/2)**x
print(res)

Submission status: Wrong Answer

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

l=[]
point=k
l.append(k)
while point>1:
    if point%2==0:
        point=point//2
    else:
        point=(point//2) +1
    l.append(point)

m=len(l)

if n>=k:
    ans1=0
    for i in range(m-1):
        count=l[i]-l[i+1]
        prob=0.5**(i+1)
        ans1+=prob*count
    ans=ans1+(n-k+1)
elif n==1:
    countn=0
    while n<k:
        n=n*2
        countn+=1
    ans=0.5**countn
else:
    ans2=0
    for i in range(m-1):
        if n>=l[i]:
            b=i
            break
        else:
            continue
        break
    ans2+=((0.5)**b)*(n-l[b]+1)
    for i in range(b,m-1):
        count=l[i]-l[i+1]
        prob=0.5**(i+1)
        ans2+=prob*count
    ans=ans2



print(ans/n)

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    count = 0
    lc = list()
    res = 0
    for i in range(1, n+1):
        if i < k:
            while i <= k:
                i = i * 2
                count += 1
                if i > k:
                    lc.append(count)
                    count = 0
    diff = n - len(lc)
    for i in range(len(lc)):
        res += 1/n * (1/2 ** lc[i])
    res += diff/n
    print(res)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
for i in range(n):
  for j in range(21):
    if  (i+1)*(2**j) >= k:
      break
  ans += 1/(n * 2**j)
  
  if j == 0:
    print(i)
    break
ans += (n-i-1)/n
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

import numpy as np

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

result = []

for i in range(n):
    num = i+1
    count = 0
    while True:
        num *= 2
        count += 1
        if num >= k:
            result.append(count)
            break

prob = 0

for j in result:
    prob += (1/n) * (0.5)**j

print(prob)

Submission status: Wrong Answer

Solution code:
import math
n,k = list(map(int, input().split()))
print(sum([(1/2)**math.ceil(math.log2(k/(i+1)))/n for i in range(n)]))

Submission status: Wrong Answer

Solution code:
import math

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

win_prob = 0
for ii in range(1,n+1):
    power = math.ceil(math.sqrt(k/ii))
    win_prob += (1/n)*(1/2)**power

print(win_prob)

Submission status: Wrong Answer

Solution code:
import math

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

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

ans = ans/N

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

print(ans)

Submission status: Wrong Answer

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

W1 = (1- (K-1)/N )
P2 = 1 - W1

out = (K-1 // 2)

W2 = (1- out/K-1 ) / 2


print(W1 + P2 * W2)

Submission status: Wrong Answer

Solution code:
import math

n, k = list(map(int, input().split()))
ans = 0
if n > k:
  ans += (n-k+1)/n

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