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:
import math
n, k = map(int, input().split())
per_pro = 1/n
total = 0
if n >= k:
  total += per_pro * (n-k+1)
if n < k:
  for i in range(1, n+1):
    a = math.ceil(math.log(k/i, 2))
    total += per_pro * (1/2)**a
else:
  for i in range(1, k):
    a = math.ceil(math.log(k/i, 2))
    total += per_pro * (1/2)**a
print(total)

Submission status: Accepted

Solution code:
import math

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

z = 0

for n in range(1,(N+1)):
    k = max(math.ceil(math.log2(K / n)), 0)
    z = z + (1/N) * ((1/2) ** k)

print(z)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
tmp=2**17
eps=10**(-10)
for i in range(1,n+1):
  if i>=k:
    ans+=1*tmp
  else:
    for j in range(1,18):
      if i*(2**j)>=k:
        ans+=tmp/(2**j)
        break
ans=ans/(n*tmp)
print(ans-eps)

Submission status: Accepted

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

l=[i+1 for i in range(N)]
L=[0 for i in range(N)]
#print(l)
for i in range(N):
    for j in range(30):
        if l[i]*(2**j)>=K:
            L[i]=1/(2**j)
            break
#print(L)
print(sum(L)/N)

Submission status: Accepted

Solution code:



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

import math



prob=max(N-K,0)
for M in range(1,min(N+1,K+1)):
	prob+=1/(2**math.ceil(math.log2(K/M)))
prob/=N
print(prob)

Submission status: Accepted

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

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

print(ans/N)

Submission status: Accepted

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

for i in range(N):
    p = 1/N
    a = i+1
    while(a<K):
        a = a*2
        p = p/2
    
    exp += p
print(exp)

Submission status: Accepted

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

import math

def readInts():
  return [int(s) for s in input().split(" ")]

def calc(K, n):
  p = math.ceil(math.log2(K / n))
  return (1.0 / 2) ** p

def main():
  N, K = readInts()
  ans = 0.0
  for n in range(1, N+1):
    r = 1.0 / N
    if n < K:
      r *= calc(K, n)
    ans += r
  print(ans)

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import math

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

print(p)

Submission status: Accepted

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

def calc_pro(ini, K):
    ans = 0
    while 1:
        if K <= ini:
            return ans
        else:
            ini *= 2
            ans += 1

ans = 0
for i in range(1,N+1):
    ans += (1/N) * (1/2) ** calc_pro(i,K)
print(ans)

Submission status: Accepted

Solution code:
import sys

class SamInput(object):
    def __init__(self):
        self.inp = []
        for i in sys.stdin:
            i = i.replace("\n", "")
            j = list(i.split())
            self.inp.append(j)

    def readln(self):
        if len(self.inp) == 0:
            return False
        else:
            return str.join(" ", self.inp.pop(0))

    def read(self):
        if len(self.inp) == 0:
            return False
        while len(self.inp[0]) == 0:
            self.inp.pop(0)
            if len(self.inp) == 0:
                return False
        return self.inp[0].pop(0)

def main():
    inp = SamInput()
    N = int(inp.read())
    K = int(inp.read())

    ttl = 0

    for i in range(N):
        dc = i + 1
        ctr = 0
        while dc < K:
            ctr += 1
            dc *= 2
        ttl += (1/N * (0.5**ctr))

    print(ttl)

    # print( (1/6) * (0.5**K + 0.5 ** (K/2) + 0.5 ** (K/3) + 0.5**(K/4) + 0.5 ** (K/5) + 0.5 ** (K/6)))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

res = 0

left = K
right = N
n = 1

# start
while left > N:
    n *= 2
    if left % 2 == 0:
        left = left // 2
    else:
        left = left // 2 + 1

# print(left, right, n)
while right > 0:
    res += (right - left + 1) / n
    n *= 2
    right = left - 1
    if left % 2 == 0:
        left = left // 2
    else:
        left = left // 2 + 1
    # print(left, right, n)
print(res / N)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import log2, ceil

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

result = 0
for i in range(1, n+1):
    if i >= k:
        result += 1 / n
    else:
        m = ceil(log2(k / i))
        result += (1 / 2**m) / n

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
while 2 ** cnt < K:
    cnt += 1

res = 0
for i in range(1, N + 1):
    while i * (2 ** cnt) >= K and cnt >= 0:
        cnt -= 1
    cnt += 1
    res += 1 / ((2 ** cnt) * N)

print("{:.12g}".format(res))

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
def sisu(num, goal):
    cnt = 0
    while num < goal:
        cnt+=1
        num*=2
    return cnt

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

print(ans/n)

Submission status: Accepted

Solution code:
import sys
import math
input = sys.stdin.readline
n,k = input().split()
n = int(n)
k = int(k)
ans = 0
if n < k:
    for i in range(1,n+1):
        s = math.log2(k / i)
        temp = (1 / 2) ** (math.ceil(s))
        ans += (temp / n)
else:
    for i in range(1,k+1):
        s = math.log2(k / i)
        temp = (1 / 2) ** (math.ceil(s))
        ans += (temp / n)
    ans += ((n - k) / n)
print(ans)

Submission status: Accepted

Solution code:
from math import ceil, log2


def main():
    N, K = map(int, input().split())
    prob = 0
    for n in range(1, N+1):
        m = ceil(log2(1.0 * K / n)) if n < K else 0
        prob += (1 / N) * (1 / 2) ** m
    print(prob)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n, k = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    if i+1 >= k:
        dice = 0
    else:
        dice = math.ceil(math.log2(k/(i+1)))
    ans += (0.5 ** dice) /n

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n, k = map(int, input().split())
    ans = 0
    if n >= k:
        ans = (n - k + 1) / n
    al = [2 ** i for i in range(1, 18)]
    for i in range(1, min(n + 1, k)):
        for j in al:
            if i * j >= k:
                ans += (1 / n) * (1 / j)
                break
    print(ans)

if __name__=="__main__":
    solve()

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):
        t = math.ceil(np.log2(K / i))
        ans += (1 / N) * np.power(0.5, t)
    else:
        ans += 1 / N

print(ans)

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if (self.parent[i] == i):
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if i < j:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


def div_ceil(a, b):
    if a % b:
        return a // b + 1
    return a // b


def main():
    n, k = intin()

    scount = 0
    counts = defaultdict(int)

    for i in range(n, 0, -1):
        while k > i:
            k = div_ceil(k, 2)
            scount += 1
        counts[scount] += 1

    ans = 0.0

    for scount, ncount in counts.items():
        ans += (ncount / n) * (1 / (2**scount))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <19/May/2019 05:51:38 PM>


#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT), Gwalior


import sys


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


def main():
    #from math import log2
    n, k = get_ints()
    ans = 0
    for i in range(1, n + 1):
        curr = (1 / n)
        x = i
        while x < k:
            x *= 2
            curr *= (1 / 2)
        ans += curr
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc126_c

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


def get_count(initial):
    cnt = 0
    point = initial
    while point < K:
        cnt += 1
        point *= 2
    return cnt


p = sum((1 / N) * 0.5 ** get_count(initial) for initial in range(1, N + 1))
print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int, raw_input().split())
ans = 0.0
for i in range(1, n+1):
    times = 0
    j = i
    while j < k:
        j *= 2
        times += 1
    ans += (0.5**times)
    #print times
print ans * (1.0 / n)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
sumA=0
index=1
while index <= n:
    if index >= k:
        sumA+=1/n
    else:
        index2=0
        while index2 < 18:
            if index*(2**index2) >= k:
                break
            index2+=1
        sumA+=(1/n)*((1/2)**index2)
    index+=1
print(sumA)

Submission status: Accepted

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

Submission status: Accepted

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

ans = [i for i in range(1, n + 1)]
ans_list = []
for i in ans:
    key = i
    cnt = 0
    while key < k:
        key *= 2
        cnt += 1
    ans_list.append(cnt)
Ans = 0
for i in range(len(ans_list)):
    Ans += ((1 / n) * pow(1 / 2, ans_list[i]))

print(Ans)

Submission status: Accepted

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

def oo(n,x):
    count = 0
    while n < x:
        count += 1
        n *=2
    return count
for i in range(1,n+1):

    ans += ((1/2)**oo(i,k))/n

print(ans)

Submission status: Accepted

Solution code:
import decimal
N, K = map(int,input().split())
ans = 0
for k in range(1,N+1):
    t = k
    c = 0
    while t < K:
        t *= 2
        c += 1
    ans += 2**(-c)
print(decimal.Decimal(ans/N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import *

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

def f(x):
    if x>=K: return 1
    kaidero = ceil(log2(K/x))
    return pow(2,-kaidero)

re = 0
for x in range(1,N+1):
    re += f(x)/N
print(re)

Submission status: Accepted

Solution code:
#!venv/bin/python

N, K = [ int(x) for x in input().split() ]
#S = input()

ans = 0.0
for dice in range(1,N+1):
    cnt = 0
    p = dice
    while p < K:
        cnt += 1
        p *= 2
    ans += (1/N) * ((1/2) ** cnt)
print(ans)

Submission status: Accepted

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

kakuritu = 0
for i in range(1,N+1):
    if K<=i:
        kakuritu += 1/N
    else:
        kaisuu = ceil(log2(K / i))

        kakuritu += 1/N * (1/2)**kaisuu

print(kakuritu)

Submission status: Accepted

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

coef = 1
pp = 1

answer = 0
if N >= K:
  answer += N-K+1 # 最初から勝てるやつ

while pp <= K:
  coef /= 2
  cnt = min(N,(K-1)//pp) - min(N,(K-1)//(pp<<1)) # 勝率がcoefであるようなものの個数
#  print(coef,cnt)
  answer += coef * cnt
  pp <<= 1
  
answer /= N
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import math

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


ans = 0
for i in range(1, N+1):

    if i >= K:
        ans += 1
    else:
        ans += 2 ** (-math.ceil(math.log2(K / i)))

print(ans / N)

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import math



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

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

print(ans/N)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
ans = 0
for i in range(1, N+1):
	if i >= K:
		ans += 1/N
	else:
		ans += (1/N) * ((1/2)**ceil(log2(K/i)))
print(ans)

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
r=0
for i in range(N):
    if i>K:r+=1
    else:r+=math.pow(2,-math.ceil((math.log2(K/(i+1)))))
print(r/N)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
def f(x):
  res=0
  while x<k:
    x*=2
    res+=1
  return res
ans=0
if n>=k:
  ans+=(n-k+1)/n
for i in range(1,min(n+1,k)):
  ans+=(1/n)*0.5**f(i)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math


def main():
  n, k = map(int, input().split())
  p = 1.0
  v = 0
  c = 0

  while True:
    w = max(n - k + 1, 0)
    v += w * p
    c += w

    if k == 1:
      break

    n = min(k - 1, n)
    k = int(math.ceil(k / 2))
    p /= 2

  #print(h)
  print('{:.9f}'.format(v / c))


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:


n, k = map(int, input().strip().split())
total = 0
for i in range(1, min(n+1, k)):
	j = i
	x = 0
	while True:
		j *= 2
		x += 1
		if j >= k:
			break
	total += (1/n)*((1/2)**x)

for i in range(k, n+1):
	total += (1/n)

# print("{0:.11f}".format(total))
print(total)

Submission status: Accepted

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

ans = 0
import math

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

print(ans)

Submission status: Accepted

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

def needcount(cycoro, K):
    c = 0
    while cycoro * 2 ** c < K:
        c += 1
    return c

ans = 0
for i in range(1, N+1):
    ans += 1/N * (1/2) ** needcount(i, K)
print(ans)

Submission status: Accepted

Solution code:
from fractions import Fraction
from decimal import Decimal

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

ans = 0
for i in range(1, n + 1):
    j = i
    times = 0
    while j < k:
        j *= 2
        times += 1
    x = Fraction(1, n) * Fraction(1, 2 ** times)
    ans += x
print("{:.10f}".format(Decimal(ans.numerator) / Decimal(ans.denominator)))

Submission status: Accepted

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

res = 0
for i in range(1, N+1):
    tmp = i
    count = 1
    for j in range(1000):
        if tmp >= K:
            break
        tmp *= 2
        count *= (1/2)
        

    res += count

    
print(res/N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(N, K):
    p = 0
    for i in range(1, N + 1):
        prob = 1 / N
        point = i
        while point < K:
            point = point * 2
            prob = prob / 2
        p += prob
    return p


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

Submission status: Accepted

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

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

Submission status: Accepted

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

TWO = [2**i for i in range(0,18)]

ans = 0
for i in range(1,N+1):
    j = 0
    for t in TWO:
        if i*t >= K:break
        j += 1
    ans += 0.5 ** j
    
print(ans/N)

Submission status: Accepted

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


def calc(x):
    cnt = 1
    while x < K:
        cnt += 1
        x *= 2
    return cnt - 1


ans = 0
for i in range(1, N + 1):
    ans += (1 / N) * (1 / (2 ** calc(i)))

print(ans)

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
coin = []
win = 0
for i in range(1,N+1):
    coin.append(math.ceil(math.log2(math.ceil(K/i))))
for i in coin:
    win +=1/(2**i)
print(win/N)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

prob = 0
for i in range(1,N+1):
    if i >= K:
        prob += 1/N
    else:
        prob += (1/N) * ((0.5) ** math.ceil(math.log2(K/i)))

print(prob)

Submission status: Accepted

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


def dice_count(dice):
    ret = 0
    while dice < k:
        dice *= 2
        ret += 1
    return ret


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math

def solve(N: int, K: int):
    p = 0
    for i in range(1, N+1):
        if i < K:
            kaisu = math.ceil(math.log2(K / i))
            p += (1 / N) * (0.5) ** kaisu
        else:
            p += (1 / N)
    print(p)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right; sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n, k = wi()


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

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
for i in range(1, N+1):
  cnt = 0
  tmp = i
  while tmp < K:
    tmp = tmp*2
    cnt += 1
  ans += 1/N*(1/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/2)**math.ceil(math.log2(k/i)))
    else:
        ans+=(n-i+1)
        break
print(ans/n)

Submission status: Accepted

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

Submission status: Accepted

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

def percentage(n):
  if n >= K:
    return 1
  
  return percentage(n * 2) / 2

ans = 0
for i in range(1, N + 1):
  ans += percentage(i) / N

print(ans)

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
counts = [0] * N

for i in range(N):
    score = i+1
    j = 0
    while True:
        if score >= K:
            counts[i] = j
            break
        score *= 2
        j += 1
ans = sum([1 / (2 ** a) for a in counts]) / N
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
result = 0.0
for n in range(1, N + 1):
    if K <= n:
        result += 1 / N
        continue
    t = (K + n - 1) // n
    x = math.ceil(math.log2(t))
    result += 1 / N * (0.5 ** x)
print(result)

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

Submission status: Accepted

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

for i in range(1, n+1):
    if k <= i:
        ans += 1 /n
        continue
    c = math.log(k/i, 2)
    c = math.ceil(c)
    ans += pow(2, -c) / n

print(ans)

Submission status: Accepted

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

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:
n, k = map(int, input().split())
ans = 0.0
prob = [1.0 / 2 ** i for i in range(20)]
for s in range(1, n + 1):
	t = 0
	while s < k:
		t += 1
		s *= 2
	ans += prob[t]
print(ans / n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math

import array
import bisect
import collections
from collections import Counter, defaultdict
import fractions
import heapq
import re

sys.setrecursionlimit(1000000)


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

def argsort(l, reverse=False):
    return sorted(range(len(l)), key=lambda i: l[i], reverse=reverse)

def argmin(l):
    return l.index(min(l))

def YESNO(ans, yes="YES", no="NO"):
    print([no, yes][ans])

II = lambda: int(input())
MI = lambda: map(int, input().split())
MIL = lambda: list(MI())
MIS = lambda: input().split()


def main():
    N, K = MI()
    prob = fractions.Fraction()
    for i in range(1, N + 1):
        if i >= K:
            prob += 1
        else:
            k = K / i
            t = math.ceil(math.log2(k))
            prob += 1 / 2**t
    return float(prob / N)


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

Submission status: Accepted

Solution code:
import math

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


# x*2^d >= k となる最小のkを求める
def calc_d(x, k):
    return int(math.ceil(math.log2(k/x)))


def submit():
    n, k = read_input()

    result = 0
    for i in range(1, n + 1):
        if i < k:
            result += math.pow((1/2), calc_d(i, k))
        else:
            result += 1.0

    print(result/n)


if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
#ABC0126-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
import math
n,k=IL()
ans=0
for i in range(1,n+1):
    if i>=k:
        ans+=1
    else:
        ans+=1/pow(2,math.ceil(math.log(k/i,2)))
print(ans/n)

Submission status: Accepted

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

def prob(i):
	score = i 
	pr = 1/n
	while score < k:
		score *= 2
		pr/=2
	return pr

ans = 0
for i in range(1, n+1):
	ans += prob(i)
print(ans)