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())

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

prob = 0
K_n = K
for i in range(1, N+1):
    count = 0
    while True:
        i *= 2
        count += 1
        if i > K:
            prob += (1/2)**count / N
            break

print(prob_cl + prob * (1 - prob_cl))

Submission status: Wrong Answer

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

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

prob = 0
K_n = K
for i in range(1, N+1):
    count = 0
    while True:
        i *= 2
        count += 1
        if i > K:
            prob += (1/2)**count / N
            break

print(prob_cl)
print(prob_cl + prob * (1 - prob_cl))

Submission status: Wrong Answer

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

for n in range(1,N+1):
    if n >= K:
        prob += 1/N
    else:
        x = math.ceil(math.log(abs((K-n)/n))/math.log(2)) + 1
        prob += 1/(N*2**x)
print(prob)

Submission status: Wrong Answer

Solution code:
import sys

def countTotalBits(num):

     # convert number into it's binary and
     # remove first two characters 0b.
     binary = bin(num)[2:]
     return(len(binary))

def lucky(threshold, K_bits, sides):
    i = 0
    lucky_win = 0
    while 2**i < threshold:
        if i == 0:
            count = 1
        else:
            count = 2**i - 2**(i - 1)
        lucky_win += count * (1 / sides) * ((1 / 2) ** (K_bits - i))
        i += 1
    lucky_win += (threshold - 2**(i - 1)) * (1 / sides) * ((1 / 2) ** (K_bits - i))
    return lucky_win

lines = sys.stdin.readlines()

sides = int((lines[0].rstrip()).split()[0])
K = int((lines[0].rstrip()).split()[1])
base_win = 0
if K == 1:
    print(1)
else:
    K_bits = countTotalBits(K)
    if K <= sides:
        base_win = (1 / sides) * (sides - K + 1)
        lucky_win = lucky(K, K_bits, sides)

    else:
        lucky_win = lucky(sides, K_bits, sides)

    print(base_win + lucky_win)

Submission status: Wrong Answer

Solution code:
import numpy as np

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) ** (int(np.log2(K / i)) + 1))
        prob.append(p_i)
else:
    p_e = 0
    for i in range(1, N+1):
        p_i = (1 / N) * ((1 / 2) ** (int(np.log2(K / i)) + 1))
        prob.append(p_i)

summer = sum(prob) + p_e

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

Submission status: Wrong Answer

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

i = 0
for i in range(N):
    if N * 2 ** i > K:
        break
p = 0
t = 0.5 ** i
for n in range(N, 0, -1):
    if n*2**i > K:
        p += t
    elif n*2**(i+1) > K:
        i += 1
        t /= 2
        p += t
print(p/N)

Submission status: Wrong Answer

Solution code:
# n, k = (int(i) for i in input().split())
n, k = 3, 10
n, k = 100000, 5

def win_num(f, k):
    i = 0
    F = f
    while F<k:
        F = f
        F = F*(2**i)
        i += 1
    if i == 0:
        return 0
    else:
        return i - 1

ls = []
for f in range(n):
    wn = win_num(f+1, k)
    ls.append((1/n) * (1/2)**wn)
print(sum(ls))

Submission status: Wrong Answer

Solution code:
import math

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

ans = 0

for i in range(min(n, k - 1)):
    i += 1
    if i == 1:
        t = int(math.log2(k)) + 1
    else:
        t = int(math.log(k, i))
    ans += (1 / 2) ** t / n

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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) ** (int(np.log2(K / i)) + 1))
        prob.append(p_i)
else:
    p_e = 0
    for i in range(1, N+1):
        p_i = (1 / N) * ((1 / 2) ** (int(np.log2(K / i)) + 1))
        prob.append(p_i)

summer = sum(prob) + p_e

print("{:.10f}".format(summer))

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int, input().split())
ans = 0
for i in range(n):
  if i >= k:
    ans += 1
  else:
    x = int(math.log(k/(i+1), 2)+1)
    ans += (1/2)**x
  # print(k/n, x, ans)
print(ans/n)

Submission status: Wrong Answer

Solution code:
import sys
import math
from decimal import Decimal
input = sys.stdin.readline

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

power_list =[] 
K_flag = N
K_temp = K

if N >= K:
    power_list.append(N-K+1)
    K_flag = K
else:
    power_list.append(0)

while K_temp > 1:
    power_list.append(0)
    K_temp /= 2
    if K_temp < K_flag:
        power_list[-1] += K_flag - math.floor(K_temp)
        K_flag = math.floor(K_temp)
    elif K_temp == K_flag:
        power_list[-1] += K_flag - math.floor(K_temp) + 1
        K_flag = math.floor(K_temp)

percentage_sum = Decimal("0.0")

for i in range(len(power_list)):
    dec_temp = math.pow(1.0/2,i)
    dec_temp = Decimal(str(dec_temp)) / Decimal(str(N))
    percentage_sum += power_list[i] * dec_temp

print(percentage_sum)

Submission status: Wrong Answer

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

import math

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

l = []
ln = n+1/2**k
l.append(math.ceil(ln-k) if ln-k>=0 else 0)
ln -= math.ceil(ln-k) if ln-k>=0 else 0

for _ in range(1,k+1):
    k/=2
    l.append(math.ceil(ln-k) if n-k>0 else 0)
    ln-=math.ceil(ln-k) if n-k>0 else 0
    if k<1:
        break

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

Submission status: Wrong Answer

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

Solution code:
import sys
import math
from decimal import Decimal
input = sys.stdin.readline

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

power_list =[] 
K_flag = N
K_temp = K

if N >= K:
    power_list.append(N-K+1)
    K_flag = K
else:
    power_list.append(0)

while K_temp > 1:
    power_list.append(0)
    K_temp /= 2
    if K_temp < K_flag:
        power_list[-1] += K_flag - math.floor(K_temp)
        K_flag = math.floor(K_temp)
    elif K_temp == K_flag:
        power_list[-1] += K_flag - math.floor(K_temp) + 1
        K_flag = math.floor(K_temp)

print(power_list)
percentage_sum = Decimal("0.0")

for i in range(len(power_list)):
    dec_temp = math.pow(1.0/2,i)
    dec_temp = Decimal(str(dec_temp)) / Decimal(str(N))
    percentage_sum += power_list[i] * dec_temp

print(percentage_sum)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
p = 0
a = k if n > k else n
for i in range(1,a+1):
    b = i
    c = 0
    while b < k:
        b *= 2
        c += 1
    print(pow(0.5, c))
    p += pow(0.5, c)
print(p/3)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math

inputs = input().split(' ')
N = int(inputs[0])
K = int(inputs[1])

prob = 0
pow = 0
if N >= K:
    prob = (N-K+1) / N
    pow += 1

while(math.ceil(K)!=1):
    print(K, prob)
    if K < N:
        prob += math.pow(0.5, pow) * (math.ceil(K) - math.ceil(K/2)) / N
    pow += 1
    K /= 2

prob += math.pow(0.5, pow) / N
print(prob)

Submission status: Wrong Answer

Solution code:
import math
def main():
    N, K = map(int, input().split())
   
    probabilitys = []   
    for i in range(1, N+1):
        if K <= i:
            break
        n = math.floor(math.log2(K/i - 1)) + 1
        p = math.pow(1/2, n)
        probabilitys.append(p)
    result = float(sum(probabilitys)/N)
    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

sum = 0.0000

for i in range(1, n+1):
    if k-1 < i:
        break
    else:
        sum = sum + ((0.5)**(math.log2(k/i)))

print(sum/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 += 0.5**int(math.log(k/i, 2)+1)
  else:
    ans += 1
    
print(ans/n)

Submission status: Wrong Answer

Solution code:
import sys

def countTotalBits(num):

     # convert number into it's binary and
     # remove first two characters 0b.
     binary = bin(num)[2:]
     return(len(binary))

lines = sys.stdin.readlines()
sides = int((lines[0].rstrip()).split()[0])
K = int((lines[0].rstrip()).split()[1])
base_win = 0
lucky_win = 0
if K == 1:
    print(1)
else:
    K_bits = countTotalBits(K)
    i = 0
    j = 0
    if K <= sides:
        base_win = (1 / sides) * (sides - K + 1)
        while 2**i < K:
            if i == 0:
                count = 1
            else:
                count = 2**i - 2**(i - 1)
            lucky_win += count * (1 / sides) * ((1 / 2) ** (K_bits - i))
            i += 1
        lucky_win += (K - 2**(i - 1)) * (1 / sides) * ((1 / 2) ** (K_bits - i))

    else:
        while 2**i < sides:
            if i == 0:
                count = 1
            else:
                count = 2**i - 2**(i - 1)
            lucky_win += count * (1 / sides) * ((1 / 2) ** (K_bits - i))
            i += 1
        lucky_win += (sides - 2**(i - 1)) * (1 / sides) * ((1 / 2) ** (K_bits - i))

    print(base_win + lucky_win)

Submission status: Wrong Answer

Solution code:
import math


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


def main():
    n, k = input_from_console()
    probability = 0.0
    if k == 1:
        probability = 1.0
    elif n == 1:
        probability = pow(1 / 2, math.ceil(math.log2(k)))
    elif n > k:
        probability += ((n - (k - 1)) + 1) / n
        for i in range(2, k):
            # print(i, pow(1 / 2, i) / n)
            x = math.ceil(math.log2(k))
            probability += pow(1 / 2, x) / n
    elif n < k:
        x = math.ceil(math.log2(k))
        for i in range(2, x + 1):
            # print(i)
            probability += pow(1 / 2, i) / n
    else:
        probability = 1/n
        for i in range(1, k):
            # print(i, 1/n * pow(1/2, math.ceil(math.log2(k))))
            probability += 1/n * pow(1/2, math.ceil(math.log2(k)))
            # probability += pow(1 / 2, i) / n

    print(probability)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
ans = 0.0000000000
if N-K>0:
    for fans in range(1, N-K+1):
        x = K//(fans)
        count = 0
        for _ in range(x):
            if x%2==0:
                count +=1
                x /= 2
            else:
                break
            ans += ( (1/N) * ((1/2)**count) )
    print(ans + ((N-K+1)/N))
   # print((N-K+1)/N + 1/N * (1/2)**count * (N-K) )
else:
    for fans in range(1, N+1):
        x = K//(fans)
        count = 0
        for _ in range(x):
            if x%2==0:
                count +=1
                x /= 2
            else:
                break
            ans += ( (1/N) * ((1/2)**count) )
    print(ans)

Submission status: Wrong Answer

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

prob = 0

for i in range(1, N+1):
    j = i
    p = 1.0
    while j < K:
        j *= 2
        p *= 0.5
    prob += p

print(prob)

Submission status: Wrong Answer

Solution code:
import math
N,K = [int(x) for x in input().split()]
p = 0
for x in range(N):
    k = K/(x+1)
    if x < K:
        k_log = math.ceil(math.log2(k))
        print(k_log)
    else:
        k_log = 0
    p += 1/N/pow(2,k_log)

print(p)

Submission status: Wrong Answer

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

result = 0
for i in range(1, n+1):
    sr = i
    count = 0
    while(sr <= k):
        sr = sr * 2
        count += 1
        
    result += (1 / n) * (0.5 ** count)    
    
print(result)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import math

n, k = [int(x) for x in input().rstrip().split(" ")]
proba = 1 / n
proba_coin_fractions = []
two_powered_list = [2 ** x for x in range(128)]
for i in range(1, n + 1):
    if i >= k:
        proba_coin_fractions.append(1.0)
        continue
    if k in two_powered_list:
        min_power_over_k = int(math.log(k / i, 2))
    else:
        min_power_over_k = int(1 + math.log(k / i, 2))
    if min_power_over_k < 1:
        min_power_over_k = 0
    proba_coin_fractions.append(1.0 / int(2 ** min_power_over_k))

proba *= sum(proba_coin_fractions)
print("%1.20f" % float(proba))

Submission status: Wrong Answer

Solution code:
import math
N,K = [int(x) for x in input().split()]
p = 0
for x in range(N):
    k = K/(x+1)
    k_log = math.ceil(math.log2(k))
    print(k_log)
    p += 1/N/pow(2,k_log)

print(p)

Submission status: Wrong Answer

Solution code:
import math

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

M = math.ceil(K/2)
flag = False
if M>N+1:
    M = N+1
    flag = True
ans = 0
l = [0 for i in range(M)]
n = math.log2(K)
in_n = int(n)
for i in range(1,M):
    if i==1:
        l[i] = .5**(in_n+1)
        continue
    if i%2 ==0:
        l[i] = l[int(i/2)]*2
    else:
        j = math.ceil(n - math.log2(i))
        l[i] = .5**(j)
ans += sum(l)/N
if not flag:
    ans += .5*(K-M)/N
    ans += (N - K + 1)/N
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
from functools import reduce
from itertools import combinations

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def pattern(k):
    a = [2]
    for i in range(1, k):
        a.append(2 ** i)
        if 2 ** i > k:
            break
    return a[::-1]


def solve():
    N, K = il()
    ans = 0 if N < K else N - K + 1
    p = pattern(K)[:N]
    k = 0
    for i in range(1, len(p) + 1):
        pk = p[k]
        k += 1
        if i * pk < K:
            k -= 1
            pk = p[k - 1]
        ans += 1 / pk
    return format(ans / N, ".20f")


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
import math
n, k = input().split()
n = int(n)
k = int(k)
p = 0
for i in range(1,n+1):
    if i >= k:
        p += (1 / n)
    else:
        p += (1 / n) * (0.5) ** math.ceil(math.log(10/i, 2))
print(p)

Submission status: Wrong Answer

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()
if len(k_list) == 0:
    ans = 1
else:
    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
if K < N:
    ans += (1/N)*(1/2) * (N-K)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import random

nums = input().split()
 
n = int(nums[0])
k = int(nums[1])

point = random.randint(1,n)
dice = point

count = 0

while 1 <= point <= k - 1:
    point = point * 2
    count = count + 1

var = 1/n + 1/2**count

print(var)

Submission status: Wrong Answer

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

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


if n >= k:
    over = n - k + 1
else:
    over = 0

x = [0]*25

x[0] = int(k / 2)

for i in range(1, 25):
    x[i] = int(x[i-1]/2)
    if x[i] == 1:
        break

while 0 in x:x.remove(0)
x = x[::-1]



y = []
y.append(1)
cum = 1
temp = min(n-1, k-2)
for i in range(len(x)):


    temp = temp - x[i]
    y.append(min(temp, x[i]))

    if temp < 0:
        y.pop(-1)
        y.append(abs(temp))
        break
    elif temp == 0:
        y.pop(-1)
        y.append(x[i])
        break

y = y[::-1]

ans = 0

temp = 1
for j in range(len(x) - i- 1):
    temp *= 1/2

for i in range(len(y)):
    temp *= 1/2

    ans += temp*y[i]
    # if y[i] == 0:
    #     break




ans = (ans + over)/n

print(ans)

Submission status: Wrong Answer

Solution code:
# cook your dish here
import math
def power(x, y): 
  
    if(y == 0): return 1
    temp = power(x, int(y / 2))  
      
    if (y % 2 == 0): 
        return temp * temp 
    else: 
        if(y > 0): return x * temp * temp 
        else: return (temp * temp) / x 
        
n,k=map(int,input().split())
summ=0
for i in range(1,n+1):
    value=0
    if i<k:
        y=k/i
        value=math.log(y,2)
        #value=int(value)
        value+=1
    po=power(0.5,value)
    summ+=po
    
summ=summ/n
print('{0:.12f}'.format(summ))

Submission status: Wrong Answer

Solution code:
from decimal import *

nk = input()
nk = nk.split(' ')
nk = [int(a) for a in nk]
n = nk[0]
k = nk[1]

r = 0

def get_fact(n):
    ret = 1
    for i in range(n):
        ret *= 2
    return ret

for i in range(n):
    current = i + 1
    count = 0
    if k <= current:
        r += 1/n
        continue
    while(current <= k):
        count += 1
        current *= 2
    else:
        r += (1/n) * (1/get_fact(count))

print(format(Decimal.from_float(r)))

Submission status: Wrong Answer

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

p = 0
m = 0
ni = n
while True:
    if ni >= k/2**m:
        pi = (ni-math.floor(k/2**m))/n*(1/2)**m
        p += pi
        ni = math.floor(k/2**m)
    m += 1
    if ni == 0:
        break

print(p)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = min([i for i in range(100) if 2**i > k])

b = [(1/n) * 0.5**(a-i) for i in range(a+1) if (a-i) > 1]
c = [1/n for i in range(n - len(b))]

print(sum(b) + sum(c) - 0.00001)

Submission status: Wrong Answer

Solution code:
import math

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

def main():
    if n == 1 and k == 1:
        print(1.0)
        return
    else:
        ans = 0

    if n == 1:
        print(1 / 2**k)
        return
    for i in range(1, n+1):
        dice = int(math.log2(k / i)+1)
        if i >= k:
            ans += 1 / n
            continue
        ans += (1 / n) * (1 / 2**dice)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
def li():
    return list(map(int, input().split()))


if __name__ == '__main__':
    [n, k] = li()

    # 最初の目がk以上で勝つ確率
    win1 = max(0, (n - k + 1) * 10 ** 4)
    # print(win1)

    # コインを投げる最大回数
    coin_max_num = len(bin(k)) - 2
    win_list = []
    candidate_list = []

    for coin in range(1, coin_max_num + 1):
        if coin == 1:
            upper = min(n, k)
            candidate = max(upper - (k + 2 ** coin - 1) // 2 ** coin, 0)
        else:
            upper = min(n, (k + 2 ** coin - 1) // 2 ** coin)
            candidate = max(upper + 1 - (k + 2 ** coin - 1) // 2 ** coin, 0)
        # print(upper)
        candidate_list.append(candidate)
        # print(candidate)
        # print()

        win_list.append(max(0, candidate * 10 ** 4 * 0.5 ** coin))
    # print(win_list)
    print((win1 + sum(win_list)) / (n * 10 ** 4))

    # upper = min(n, k)
    # win_list.append(max(0, (upper - (k + 2**1-1) // 2) / n) * 0.5 ** 1)

    # upper = min(n, (k + 1) // 2)
    # win_list.append(max(0, (upper - (k+2**2-1) // 2**2) / n) * 0.5 ** 2)
    # print(99996 / 100000 + 2 / 100000 * 0.5 + 1 / 100000 * 0.5 ** 2 + 1 / 100000 * 0.5 ** 3)

Submission status: Wrong Answer

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

def win_num(f, k):
    i = 0
    F = f
    while F<k:
        F = f
        F = F*(2**i)
        i += 1
    if i == 0:
        return 0
    else:
        return i - 1

ls = []
for f in range(n):
    wn = win_num(f+1, k)
    ls.append((1/n) + (1/2)**wn)
print(sum(ls))

Submission status: Wrong Answer

Solution code:
# C
import sys, math

n, k = map(int,input().split())
# ans = max((n-k-1)/n, 0)
# count = 1
# k2 = k
# while k2 > 1:
#         k3 = k2
#         k2 = math.ceil(k/(2**count))
#         ans += (1/(2**count)) * ((k3-1)-k2) / n
#         count += 1
# print(ans)
ans = 0
for i in range(30):
        if math.ceil(k * (1/(2**i))) == 1:
                break
        ans += k * (1/(2**i)) * max(n - math.ceil(k * (1/(2**i))), 0)

print(ans)

Submission status: Wrong Answer

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

cnt=0
for i in range(17):
  if 2**i<k:
    cnt+=1
  else:
    break

c=1
for j in range(n-1):
  d=0
  for i in range(17):
    if (j+1)*(2**i)<k:
      d+=1
    else:
      c+=2**(cnt-d)

print(c/n*(2**cnt))

Submission status: Wrong Answer

Solution code:
n,k=input().split()
N=int(n)
K=int(k)
A=1
P=(N-K+1)/N
Q=0
import math
while A<=K-1:
  a=math.log2(K/A)
  f=float(a)
  if f==0:
    b=a
  else:
    b=a-f+1
  Q=Q+(1/N)*(2**b)
  A=A+1
print(P+Q)

Submission status: Wrong Answer

Solution code:
import math
N, K = (int(x) for x in input().split())
prob = 0
log2 = math.log(2)
logK = math.log(K)
for i in range(1,N+1):
    n = math.ceil((logK - math.log(i)) / log2)
    prob += 0.5 ** n
    #print(0.5 ** n)
print(prob / N)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
N, K = [int(i) for i in input().split()]

kaku = []

j = 0
while True:
    if 1 * (2**j) > K:
        kaku.append(Fraction(1, N) * Fraction(1, 2**j))
        break
    j += 1
    
for i in range(2, N+1):
    while True:
        if j == 0:
            kaku.append(Fraction(1, N))
            break
        elif i * (2**j) < K:
            kaku.append(Fraction(1, N) * Fraction(1, 2**(j+1)))
            break

        
        if j > 0:
            j -= 1

print(float(sum(kaku)))

Submission status: Wrong Answer

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

ls = []

def multiply(ls):
    result = []
    for i in range(len(ls)):
        result.append(pow(N, -1) * ls[i])
    return result

if N < K:
    for i in range(1, N + 1):
        p = i
        cnt = 0
        while p < K:
            p *= 2
            cnt += 1
        ls.append(pow(2, -cnt))
    print(sum(multiply(ls)))
else:
    for i in range(1, K):
        p = i
        cnt = 0
        while p < K:
            p *= 2
            cnt += 1
        ls.append(pow(2, -cnt))
    print(1 - sum(multiply(ls)))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
cnt_list = []
if N < K:
    for i in range(1, N + 1):
        cnt = 0
        while i < K:
            i *= 2
            cnt += 1
        cnt_list.append(cnt)
    print(1 - sum([(1 / N) * (1 - 0.5 ** i) for i in cnt_list]))
if N > K:
    for i in range(1, K):
        cnt = 0
        while i < K:
            i *= 2
            cnt += 1
        cnt_list.append(cnt)
    print(1 - sum([(1 / N) * (1 - 0.5 ** i) for i in cnt_list]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

ans = 0

def calcuration(cal_range) :
  for i in range(cal_range) :
    Ncoin = 0
    dice = i + 1
    while dice > K :
      Ncoin += 1
      dice *= 2
    global ans
    print(2 ^ Ncoin) 
    ans += 1 / (2 ^ Ncoin)

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

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int, input().split())
ans = 0
for i in range(n):
  x = int(math.log(k/(i+1), 2)+1)
  ans += (1/2)**x
  if i >= k:
    ans += 1
  # print(k/n, x, ans)
print(ans/n)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
answer = 0
i = 1
while n < k:
    i *= 2
    k = k//2
answer += (n-k) / (i*n)
while 1 < k:
    i *= 2
    answer += (k-k//2) / (i*n)
    k -= k//2
i *= 2
answer += (k-k//2) / (i*n)
print(answer)

Submission status: Wrong Answer

Solution code:
N,K = map( int, input().split())
#a = [0 for in range(K)]
l = [0]
win = 0
if N>=K:
  win = N-K+1
  l[0] = N-K+1
now = K-1
cnt = 2
nN = N
while now>=1:
  nx = now // 2
  if N > now:
    a = now-nx
  elif now >= nN > nx:
    a = N - nx
  else:
    a = 0
  l.append(a)
  now = nx
  cnt *= 2
ll = len(l)
pp = 1
for i in range(ll):
  l[ll-i-1] *= pp
  pp *= 2
suml = sum(l)
print( suml/(pp/2))

Submission status: Wrong Answer

Solution code:
import sys


def main():
    N, K = [int(x) for x in sys.stdin.readline().rstrip().split()]

    ans = 1
    for i in range(N):
        ans -= (1 / N) * (1 / 2) ** (N + 1 - i)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Answer = 0

for i in range(n):
  s = i+1
  while k < 2**s:
    s += 1
  Answer += 1/n *((1/2)**(s-1))

print(Answer)

Submission status: Wrong Answer

Solution code:
N = 100000 
K = 5
prob = 0
list = []
for n in range(1, N+1):
  #print(n)
  #print("hogehoge")
  if(K <= n):
   prob = prob + 1
   continue
  else:
   #print(bin(n))
   #print(bin(K))
   len_bin_n = len(str(bin(n)))
   len_bin_k = len(str(bin(K)))
   min_rest_number_of_front = len_bin_k - len_bin_n
   if(K <= n * pow(2, min_rest_number_of_front)):
    last = min_rest_number_of_front
    list.append(last)
    #hoge = hoge + pow(2, min_rest_number_of_front)
    #prob = prob + 1/pow(2,min_rest_number_of_front)
    #print(1/pow(2,min_rest_number_of_front))
   else:
    last = min_rest_number_of_front + 1
    list.append(last)
    #print(1/pow(2,min_rest_number_of_front+1))
hoge = list[len(list)-1]

for i in range(len(list)):
    hige = hoge - list[i]
    prob = prob + pow(2,hige)
    
result = (1/N) * (prob / pow(2,hoge))
print(result)

Submission status: Wrong Answer

Solution code:
n , k = map(int,input().split())
hoge = k / n
i = 0
while(hoge > 2**i):
    i += 1
j = 0
while(k > 2**j):
    j += 1

tmp = 0
if i == 0:
    i += 1
for k in range(i,j+1):
    tmp += (0.5)**k
    print(i,j,k,tmp)
tmp += n - (j+1-i)
ans = tmp / n
print(ans)

Submission status: Wrong Answer

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


def kaisuu():

	a = 0
	b = 1

	while True:
		b = b*2
		a+=1 
		if b > k:
			break
			
	return a
			
max_count = kaisuu()

kakuritu = 0
for _ in range(0,n):
		
	if n>k:
		kakuritu += 1/n * 1/2
	else:
		kakuritu += 1/n * pow(1/2,max_count)
		max_count-=1

print(kakuritu)

Submission status: Wrong Answer

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

total = 0
if l[0] > l[1]:
    for i in range(1,l[0]+1):
        if i >= l[1]:
            total += (l[0] - l[1] + 1)/l[0]
            break
        else:
            total += (1/l[0]) * pow(0.5,l[0]-i+2)
else:
    for i in range(1,l[0]+1):
        total += (1/l[0]) * pow(0.5,l[0]-i+2)
        
print(total)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
k = K
kl = [K]
while k > 1:
    k = k//2
    kl.append(k)
ans = 0
for i in reversed(range(len(kl))):
    if N > kl[i-1]:
        ans += (kl[i-1]-kl[i])*(0.5**i)
    else:
        break
print(ans/N)

Submission status: Wrong Answer

Solution code:
import math

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

probability = 0

lastend = N + 1
for i in range(K):
    if N < K and i < round(math.sqrt(K/N)):
        continue
    core = lastend - math.ceil(K/(2**i))
    lastend = math.ceil(K/(2**i))
    #print(i,core,lastend)
    probability += (core/N)*((1/2)**i)

print(probability)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = list(map(int, input().split()))
a = []
for i in range(1, n[0]+1):
    a.append(i)
e = 0

for j in range(len(a)):
    c = a[j]
    d = 0
    while c <= n[1]:
        c *= 2
        d += 1
        if c >= n[1]:
            e += (1/a[-1] * (1/2)**d)
print(e)

Submission status: Wrong Answer

Solution code:
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(15)]
    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(sum(cc) /N)
            
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

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


times = 0
total = 1
while total < K:
    total *= 2
    times += 1

bo = N * (2 ** times)    


#num = 2**(times-1)-1
num = 0
num2 = 1
for i in range(times-1):
    num += num2
    num2 *= 2

#print(times)
#print(num)
#print(bo)

print(num/bo)

Submission status: Wrong Answer

Solution code:
import math

def getCount(K,i) :
    return math.log(K/i,2)

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

for i in range(1,N+1) :
    count = math.ceil(getCount(K,i))
    if count == 0 :
        count = 1
    elif count < 0 :
        score += 1/N
        continue
    score += 1/N * (1/2)**count
print(score)