Problem:


Score : 300 points

Problem Statement

Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:

Throw the die. The current score is the result of the die.

As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.

The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.

You are given N and K. Find the probability that Snuke wins the game.

Constraints

1 ≤ N ≤ 10^5

1 ≤ K ≤ 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.

Sample Input 1

3 10

Sample Output 1

0.145833333333

If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^4 = \frac{1}{48}.

If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^3 = \frac{1}{24}.

If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^2 = \frac{1}{12}.

Thus, the probability that Snuke wins is \frac{1}{48} + \frac{1}{24} + \frac{1}{12} = \frac{7}{48} \simeq 0.1458333333.

Sample Input 2

100000 5

Sample Output 2

0.999973749998



Sample input:
3 10


Sample output:
0.145833333333

Submission status: Accepted

Solution code:
n,k=map(int,input().split(' '))
i = 0
while pow(2,i) < k:
    i += 1 #k=5~8ではi=3
q = 1;rate = 0;j = 0
while q <= n:
    while q*pow(2,(i-j)) >= k:
        j += 1
    j -= 1
    rate += min(1/pow(2,(i-j)),1)
    q += 1
print(rate/n)

Submission status: Accepted

Solution code:
def main():
  N, K = (int(x) for x in input().split())
  ret = 0
  for d in range(1, N + 1):
    cc = 0
    d = (K-1)//d
    while d > 0:
      d //= 2
      cc += 1
    ret += 1 / (N * pow(2, cc))
  print(ret)
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split(" ")]
P = []
ans = 0

def calc_num(n):
    num = 0
    while(n < K):
        num += 1
        n *= 2
    return num


for i in range(1,N+ 1):
    calc = calc_num(i)
    if calc:
        P.append(calc_num(i))
    else:
        P.append(-1)

for p in P:
    if p > 0:
        ans += (1/N) * ((1/2) ** p)
    else:
        ans += 1/N

print(ans)

Submission status: Accepted

Solution code:
# solution
import io

n, m = map(int, input().split())
counter = 0
for i in range(1, n + 1):
    j = 0
    while i * 2**j < m:
        j += 1
    counter += 1 / 2**j
print(counter / n)

Submission status: Accepted

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

ans = 0
for s in range(1, N+1):
    num = 0
    p = 1
    while s < K:
        s *= 2
        num += 1
        p /= 2
    ans += p

print(ans/N)

Submission status: Accepted

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

print(w*(1/N))

Submission status: Accepted

Solution code:
import sys
from math import log2, ceil

n, k = map(int, sys.stdin.readline().split())

def main():
    res = 0
    for i in range(1, n + 1):
        denom = 1
        while i < k:
            i *= 2
            denom *= 2
        res += 1 / denom
    res /= n
    print(res)   

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
for i in range(99999):
  if 2**i<k:
    continue
  else:
    start=i
    break

key=start
def p(n):
  return 2**(n)

ans=1
for i in range(2,n+1):
  if i<k:
    if i*p(key-1)<k<i*p(key):
      pass
    elif i*p(key-1)==k:
      key-=1
    elif i*p(key-2)<k<i*p(key-1):
      key-=1
    ans+=p(start-key)
  else:
    ans+=p(start)
print('{:.11f}'.format(ans/(p(start)*n)))

Submission status: Accepted

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

ans=0
for i in range(1,n+1):
    cnt=0
    while i<k:
        i *=2
        cnt+=1
    ans+=(0.5**cnt)    

print(ans/n)

Submission status: Accepted

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

x = 1
while x < K:
    x = 2 * x

for i in range(N):
    target = N - i
    tmp = val
    while tmp * target < K:
        num += 1
        tmp = 2 * tmp
    val = tmp
    ans += x // tmp
print('{:.10g}'.format(ans / (N * x)))

Submission status: Accepted

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

total = 0
for i in range(1, n+1):
    score = i
    count = 0
    while score < k:
        score <<= 1
        count += 1
    total += 1 / (2 ** count)

print('{:.10g}'.format(total / n))

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    res = 0
    # 1 ~ n まで、表がでる確率としてn_回必要であると考える
    # 成功率から(1/2)^nとなる
    # それを v = 1,2...nまで合計すれば大丈夫
    for n_ in range(1,n+1):
        tmp = 1.0
        n2 = n_
        while n2 < k:
            n2 *= 2
            tmp /= 2.0
        res += tmp
    print("%.010f"%(res/n))
if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, read().split())
ans = 0
for i in range(1, n + 1):
    cnt = 0
    check = i
    while k > check:
        check *= 2
        cnt += 1
    if cnt == 0:
        ans += 1 / n
    else:
        ans += 0.5 ** cnt * (1 / n)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
dice,goal=map(int,input().split())
ans=[]
for i in range(1,dice+1):
  Q=1/dice
  point=i
  cnt=0
  while point<goal:
    cnt+=1
    point*=2
  ans.append(Q*(0.5)**cnt)
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
import math
# コインを連続i回表出さないといけないサイコロの目
# n >= k ならi=0

i=1
ans=max(0,(n-k+1)/n)

while k*2**(-i+1) > 1:
    a = min(n,math.ceil(k*2**(-i+1))-1)
    b = math.ceil(k*2**(-i))
    ans+=max(a-b+1,0) * 2**(-i) /n
    i+=1
print(ans)

Submission status: Accepted

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

X=0
Ans=0
for i in range(N):
    if i+1<K:
        X=math.log2(K/(i+1))
        X2=math.ceil(X)
        Ans+=((0.5)**X2)*(1/N)
    else:
        Ans+=((N-K+1)/N)
        break


print(Ans)

Submission status: Accepted

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

ans = 0
for i in range(1, N + 1):
    base = 1 / N
    while i < K:
        base *= 1 / 2
        i *= 2
    ans += base

print(ans)

Submission status: Accepted

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

if K <= N:
    pos = (N - K + 1) / N
else:
    pos = 0

if pos != 1:
    for i in range(1,K):
        if i == N+1:
            break
        point = i
        cnt = 0
        while point < K:
            point *= 2
            cnt += 1
        pos += (1/N) * (0.5 ** cnt)

print(pos)

Submission status: Accepted

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

res = 0

for i in range(N+1)[1:]:
  j = 0
  while i*(2**j) < K:
    j += 1
  res += (1/N) * ((1/2) ** j)

print(res)

Submission status: Accepted

Solution code:
import collections, math, bisect
from fractions import Fraction

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

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

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

if local:
    start=time.time()


N, K = ints()

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

ans*=oneprob

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

print("{:.20f}".format(float(ans)))

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

Submission status: Accepted

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

Submission status: Accepted

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

def maxcount(n,k):
    if n>=K:
        return k
    else:
        k+=1
        return maxcount(2*n,k)
    
for i in range(1,N+1):
    if i<K:
        ans+=(1/N)*((1/2)**maxcount(i,0))
    else:
        ans+=1/N
print('{:.12f}'.format(ans))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
a = [1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072]
for i in range(1, n+1):
    res = k/i
    for j in range(len(a)):
        if res <= a[j]:
            res = j
            break
    ans += (1/n)*(0.5**res)
print(ans)

Submission status: Accepted

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

for i in range(1,N+1):
  count = i
  p = 1/N
  while count<K:
    count = count*2
    p = p/2

  ans = ans + p

print(ans)

Submission status: Accepted

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

p = 0
for i in range(1, N+1):
    cnt = 0
    x = i
    while True:
        x *= 2
        cnt += 1
        if x >= K:
            break
    if i <= K-1:
        p += (1/N)*(1/2)**(cnt)
    else:
        p += 1/N

print(p)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
sum=0
#N面サイコロ、得点K
#K-1以下の得点ならコインを振り続ける
for i in range(1,N+1):
  target=i
  count=0
  while(target<K):
    target*=2
    count+=1
  sum+=(1/N)*(0.5**count)
print(sum)

Submission status: Accepted

Solution code:
import numpy as np
N,K = map(int,input().split())
P = np.zeros(N) + (1 / N)
A = np.arange(1,N+1)
while np.any(A < K):
    P[A < K] = P[A < K] / 2
    A[A < K] = A[A < K] * 2
print(np.sum(P))

Submission status: Accepted

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

print(ans/n)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
win = 0
for i in range(1, n+1):
    index = 0
    while pow(2, index) < k/i:
        index += 1
    win += pow(0.5, index)/n
print(win)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N,K = map(int,input().split())
c = [0] * N
for i in range(1,N+1):
    j = i
    d = 0
    while j < K:
        j *= 2
        d += 1
    c[i-1] = d
s = 0
for k in c:
    s += (0.5) ** k
print(s/N)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import math


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

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

Submission status: Accepted

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

def double(i,k):
    while i < k :
        i *= 2
    return i

for i in range(1,n+1):
    ans += (i / double(i,k)) / n
print(ans)

Submission status: Accepted

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

for i in range(n):
  tmp = 1 / n
  now = i + 1
  while now < k:
    now *= 2
    tmp /= 2
  n_sum += tmp
print(n_sum)

Submission status: Accepted

Solution code:
import math
n, k = [int(e) for e in input().split()]
sum = 0.0
for i in range(1, n+1):
  if i >= k:
    sum += 1.0
  else:
    sum += 0.5 ** math.ceil(math.log2(k/i))
print(sum / n)

Submission status: Accepted

Solution code:
import math

def calc(x,k,n):
    m = math.ceil(math.log2(k/x))
    y = 2**m
    if x >= k:
        return 1
    else:
        return 1/y
n,k = map(int,input().split())
ans = 0.0
for x in range(1,n+1):
    tmp = calc(x,k,n)
    ans += tmp
print(ans/n)

Submission status: Accepted

Solution code:
import numpy as np

N, K = map(int, input().split())
P = 0
for p in range(1, N+1):
  i = max(0, np.ceil(np.log2(K/p)))
  P += (1/N)*(0.5**i)
  
print(P)

Submission status: Accepted

Solution code:
import math

inputted = list(map(int, input().split()))
N = inputted[0]
K = inputted[1]

num_of_rolls = lambda dice, K: max(0, math.ceil(math.log2(K / dice)))
continius_probability = lambda rolls: (1 / 2) ** rolls
dice_probablility = lambda N: 1 / N

answer = sum([continius_probability(num_of_rolls(dice, K)) for dice in range(1, N + 1)])
answer *= dice_probablility(N)

print(answer)

Submission status: Accepted

Solution code:
import math

inputted = list(map(int, input().split()))
N = inputted[0]
K = inputted[1]

num_of_rolls = lambda dice, K: max(0, math.ceil(math.log2(K / dice)))
continius_probability = lambda rolls: (1 / 2) ** rolls
dice_probablility = lambda N: 1 / N

answer = 0
for dice in range(1, N + 1):
    answer += continius_probability(num_of_rolls(dice, K))
answer *= dice_probablility(N)

print(answer)

Submission status: Accepted

Solution code:
import math

inputted = list(map(int, input().split()))
N = inputted[0]
K = inputted[1]

num_of_rolls = lambda dice, K: max(1, math.ceil(math.log2(K / dice)))
continuous_probability = lambda rolls: (1 / 2) ** rolls
expectation = lambda N: 1 / N

answer = 0
for dice in range(1, N + 1):
    if dice >= K:
        answer += 1
    else:
        num = num_of_rolls(dice, K)
        answer += continuous_probability(num)
answer *= expectation(N)

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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:
    X = math.ceil(math.log2(K)-math.log2(i))
    ans += ((1/N)*((1/2)**X))
print(ans)

Submission status: Accepted

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

s = 0
for i in range(1,N+1):
    c = 0
    while i*2**c < K:
        c +=1
    s += 1/(N*(2**c))

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from fractions import Fraction

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

Submission status: Accepted

Solution code:
import math
from fractions import Fraction

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

Submission status: Accepted

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

ans = 0
for i in range(1, N+1):
    k = 0
    while i*2**k < K:
        k += 1
    ans += (1/N)*(1/2)**k

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
n, k = map(int, input().split())

"""
さいころの目がiとするとき、得点をk以上にするには
int(log(i))+x >= kを満たすxの回数。つまりk-log(i)回連続で表が出れば良い
"""
import math
ans = 0 # 後でnで割る

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

Submission status: Accepted

Solution code:
import math
from decimal import Decimal

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

win = 0

for i in range(1, N+1):
    if K - i < 1:
        win += 1
        continue

    win += (1/2)**(math.ceil(math.log2(K/i)))
    #print((math.ceil(math.log2(K/i))))

print('{:.10g}'.format(Decimal(win/N)))

Submission status: Accepted

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

ans = 0
for n in range(1, N+1):
    if n >= K:
        ans += 1
        continue
    ans += (1/2) ** math.ceil(math.log2(K / n))

print(ans / N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
dice = np.arange(1, N+1, dtype=np.int32)
need = np.zeros(N, np.int32)

for i in range(20):
    target = dice < K
    need[target] += 1
    dice[target] <<= 1 #2倍

rate = (.5) ** need
answer = rate.sum() / N
print(answer)
#

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
dice = np.arange(1, N+1, dtype=np.int32)
need = np.zeros(N, np.int32)

for i in range(20):
    target = dice < K
    need[target] += 1
    dice[target] <<= 1 #2倍

counter = np.bincount(need, minlength=20)
power = np.full(20, .5, dtype=np.float64)
power[0] = 1
np.cumprod(power, out=power)

answer = (counter * power).sum() / N
print(answer)
#

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
dice = np.arange(1, N+1, dtype=np.int32)
need = np.zeros(N, np.int32)

for i in range(20):
    target = dice < K
    need[target] += 1
    dice[target] <<= 1 #2倍

power = (.5) ** need
answer = power.sum() / N
print(answer)
# 58

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, k = map(int, input().split())
ans = 0
for p in range(1, n + 1):
    c = 0
    while (True):
        if p >= k:
            ans += (1 / n) * (1 / 2) ** c
            break
        p *= 2
        c += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
answer = 0
for x in range(1, N+1):
    y = 0
    while True:
        if x * 2 ** y >= K:
            break
        y += 1
    answer += (.5) ** y

answer /= N
print(answer)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
p = 1 / N
P = [p] * N
for i in range(min(N,K-1)):
    n = i + 1
    while n < K:
        P[i] *= (0.5)
        n = 2 * n
print(sum(P))

Submission status: Accepted

Solution code:
from math import log, ceil
N,K = map(int, input().split())
ans = [1/N * ((1/2)**ceil(log(K/(s+1))/log(2)) if s+1<K else 1) for s in range(N)]
print(sum(ans))

Submission status: Accepted

Solution code:
import math

n,m = map(int,input().split())
p = 0
for i in range(1,n+1):
  if i>=m:
    p += 1/n
  else:
    a = math.ceil(math.log2(m/i))
    p += (1/n)*((1/2)**a)
print(p)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
prob = 0
point = 0
for cube in range(1,n+1):
    if cube <= k-1:
        point = cube
        t = 0
        while True:
            point = point*2
            t += 1
            if point >= k:
                break
        prob += 1/n * ((1/2)**t)
    else:
        prob += 1/n
print(prob)

Submission status: Accepted

Solution code:
import math
n, k = [int(i) for i in input().split()]
sum = 0
for i in range(1, n+1):
    l = 0
    while i * (2 ** l) < k:
        l += 1
    sum += 1 / (2 ** l * n)
print(sum)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
def P(K):
	a=[K]
	b=K
	while b>1:
		b=(b+1)//2
		a.append(b)
	return  a
a=P(K)
#print(a)
for i in range(len(a)):
	if a[i]<=N:
		b=i
		break
#print(b)
ans=(N-a[b]+1)*((1/2)**b)
for j in range(b,len(a)-1):
	ans+=(a[j]-a[j+1])*((1/2)**(j+1))
#	print((a[j]-a[j+1])*((1/2)**(j+1)))
#	print(i)
print(ans/N)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
prob = 0
#サイコロの確率(1/n) 

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n,k=MI()
probab=0
for i in range(1,n+1):
    s=i
    count=0
    while s<k:
        s*=2
        count+=1
    probab+=1/(2**(count))
print(probab/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
a = [0] * n
for i in range(1,n+1):
    a[i-1] = 1 / (n * (2 ** math.ceil(math.log2(max(k/i, 1)))))

print(sum(a))

Submission status: Accepted

Solution code:
import math
a,b = map(int,input().split())
ans = 0
count = 0
dummy2 = 1/a
for i in range(1,a+1):
  while(1):
    if i >= b:
      break
    i *= 2
    count += 1
    #print(i,count)
  ans += ((1/2)**count)*dummy2
  count = 0
print(ans)

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

_NUMINT_ALL = list(range(10))


def main():
    ans = solve()
    if ans is not None:
        print(ans)


def solve():
    N, K = iip(False)

    ans = 0

    for i in range(1, N+1):
        cur = 1
        c2 = i
        for j in range(1000):
            if c2 >= K:
                break
            c2 *= 2
            cur /= 2
            #print(i, c2, cur)
        ans += (1/N) * (cur)

    print(ans)






#####################################################ライブラリ集ここから

def iip(listed=True, num_only=True):  # 数字のinputをlistで受け取る
    if num_only:
        ret = [int(i) for i in input().split()]
    else:
        ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def saidai_kouyakusuu(a, b):  # 最大公約数
    for i in soinsuu_bunkai(a):
        if b % i == 0:
            b //= i
    return a * b


def sort_tuples(l, index):  # タプルのリストを特定のインデックスでソートする
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  # リストの中身の個数を種類分けして辞書で返す
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  # listの中身を取り出す時、listからはみ出たり
    if index >= len(l):                      # マイナスインデックスになったりするのを防ぐ
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def iipt(l, listed=False, num_only=True):  # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed, num_only=num_only))
    return ret


def sortstr(s):  # 文字列をソートする
    return "".join(sorted(s))


def iip_ord(startcode="a"):  # 文字列を数字の列に変換する(数字と文字は1:1対応)
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  # TrueFalseや1, 0をYesNoに変換する
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
    for i in s:
        print(i)


def bitall(N):  # ビット全探索用のインデックスを出力
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  # リストの中身をスペース区切りで出力する
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  # リストの中身を改行区切りで出力する
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  # 素因数分解
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  # nCrをmodを使って計算する
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):  #  modnにおける逆元を計算
    return power(n, mod - 2)


def power(n, p, mod_=mod):  # 繰り返し二乗法でn**p % modを計算
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

n, k = load_list()

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

print(p)

Submission status: Accepted

Solution code:


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

ret = 0

for i in range(1, n+1):
    tmp = 1.0 / n
    now = i
    while now < k:
        now *= 2
        tmp /= 2
    ret += tmp

print(ret)

Submission status: Accepted

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

A = 0
for i in range(N):
  j = 0
  while True:
   if K / (i+1) / 2**j <= 1:
    break
   else:
    j+=1
  A += 1/N * (0.5)**j

print(A)

Submission status: Accepted

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