AtCoder Beginner Contest 126 - Dice and Coin

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-----
3 10

-----Sample Output-----
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.

Source: atcoder | Difficulty: EASY


Solutions:
(n, k) = map(int, input().split())
ans = 0
w = 1
for i in range(n, 0, -1):
	while i * w < k:
		w *= 2
	ans += 1 / w
print(ans / n)


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


(N, K) = map(int, input().split())
t = 0
import math
for x in range(1, min(N, K - 1) + 1):
	t += 1 - pow(0.5, math.ceil(math.log2(K / x)))
print(1 - t / N)


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


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


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


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


import math
(n, k) = map(int, input().split())
ans = 0
for i in range(1, n + 1):
	a = max(math.ceil(math.log2(k / i)), 0)
	ans += 0.5 ** a
print(ans / n)


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


(N, M) = map(int, input().split())
if M == 1:
	print(1)
	return
import math
prob = 0
for i in range(1, N + 1):
	if i >= M:
		prob += 1 / N
	else:
		prob += 1 / N * 1 / 2 ** math.ceil(math.log(M / i, 2))
print(prob)


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


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


(n, k) = map(int, input().split())
if n >= k:
	p = (n - k + 1) / n
else:
	p = 0
for i in range(1, min(n + 1, k)):
	q = 1 / n
	while i < k:
		i *= 2
		q /= 2
	p += q
print(p)


from math import ceil as c
from math import log2 as l
(n, k) = map(int, input().split())
ans = 0
for i in range(1, n + 1):
	if i < k:
		ans += 0.5 ** c(l(k / i)) / n
	else:
		ans += 1 / n
print(ans)


import math
(N, K) = map(int, input().split())
a = 0
for i in range(1, N + 1):
	if i < K:
		a += 0.5 ** math.ceil(math.log2(K / i))
	else:
		a += 1
print(a / N)


(N, K) = [int(s) for s in input().split()]
a = 0
for i in range(N):
	x = i + 1
	n = 0
	while x < K:
		n += 1
		x *= 2
	a += 2 ** (-n)
print(a / N)


(n, k) = map(int, input().split())
s = 0
for i in range(1, n + 1):
	h = i
	t = 0
	while h < k:
		h = 2 * h
		t += 1
	s = s + (1 / 2) ** t
print(s / n)


import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
input = sys.stdin.readline

def RD():
	return input().rstrip()

def F():
	return float(input().rstrip())

def I():
	return int(input().rstrip())

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

def MF():
	return map(float, input().split())

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

def TI():
	return tuple(map(int, input().split()))

def LF():
	return list(map(float, input().split()))

def Init(H, W, num):
	return [[num for i in range(W)] for j in range(H)]

def main():
	(N, K) = MI()
	D = deque()
	D.append(1)
	num = 1
	index = 0
	while num <= K:
		num *= 2
		index += 1
		D.append(num)
	ans = 0
	for i in range(1, N + 1):
		temp = K / i
		index2 = bisect_left(D, temp)
		ans += D[index - index2]
	print(ans / (N * D[index]))

def __starting_point():
	main()
__starting_point()


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


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


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


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


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


(D, P) = map(int, input().split())
ans = 0.0

def func(i):
	t = 0
	while i < P:
		i *= 2
		t += 1
	return t
for i in range(1, D + 1):
	ans += float(1 / D) * float((1 / 2) ** func(i))
print(ans)


import math
(n, k) = map(int, input().split())
ans = 0
for i in range(1, n + 1):
	t = 1
	ii = i
	while ii < k:
		ii *= 2
		t /= 2.0
	ans += t
ans = float(ans) / n
print(ans)


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)


(N, K) = map(int, input().split())
tmp = 1
num_cnt = 0
while K > tmp:
	tmp *= 2
	num_cnt += 1
nums_list = []
for i in range(1, N + 1):
	for j in range(num_cnt + 1):
		if i * 2 ** j >= K:
			nums_list.append((1 / 2) ** j)
			break
print(sum(nums_list) * (1 / N))


(N, K) = map(int, input().split())
b = 0
c = 0
for i in range(N):
	b = 1
	j = i + 1
	while j < K:
		j *= 2
		b /= 2
	c += b
d = c / N
print(d)


(n, k) = list(map(int, input().split()))
res = 0
for i in range(1, n + 1):
	p = 1
	t = 1
	while i * t < k:
		t *= 2
		p /= 2
	res += p / n
print(res)


import math
(n, k) = map(int, input().split())
p = 0
for i in range(n):
	p += 0.5 ** max(0, math.floor(math.log2((k - 0.5) / (i + 1)) + 1))
print(p / n)


(n, k) = map(int, input().split())
d = 0
for i in range(1, n + 1):
	a = i
	b = 0
	c = 0
	while a < k:
		a = a * 2
		b = b + 1
	c = (1 / 2) ** b
	d = d + c
print(d / n)


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


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


from math import ceil, log2
(n, k) = map(int, input().split())
print(sum((0.5 ** max(ceil(log2(k / i)), 0) for i in range(1, n + 1))) / n)


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


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


(N, K) = map(int, input().split())
ls = [0]
for i in range(1, N + 1):
	if i >= K:
		ls.append(1)
	else:
		p = 1
		f = K // i
		if K % i == 0:
			f -= 1
		while f != 0:
			f = f // 2
			p = p / 2
		ls.append(p)
ans = sum(ls) / N
print(ans)


(a, b) = map(int, input().split())
ans = 0
for i in range(1, a + 1):
	tmp = 1
	while i * tmp < b:
		tmp *= 2
	ans += 1 / a * (1 / tmp)
print(ans)


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


(N, K) = map(int, input().split())
P = 0
for i in range(N):
	temp_i = i + 1
	temp_P = 1 / N
	while temp_i < K:
		temp_i *= 2
		temp_P *= 1 / 2
	P += temp_P
print(P)


(N, K) = map(int, input().split())
ans = 0
for i in range(1, N + 1):
	j = 0
	while True:
		if K <= i * 2 ** j:
			ans += 1 / N * (1 / 2) ** j
			break
		j += 1
print(ans)


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


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


(n, K) = map(int, input().split())
p = 1 / n
ans = 0
for result in range(1, n + 1):
	k = K
	k /= result
	cnt = 0
	while k > 1:
		k /= 2
		cnt += 1
	ans += p * 0.5 ** cnt
print(ans)


(N, K) = input().split()
N = int(N)
K = int(K)
import math
M = math.log(K, 2)
P = sum([1 / 2 ** max(math.ceil(M - math.log(i, 2)), 0) for i in range(1, N + 1)]) / N
print(P)


import sys
input = sys.stdin.readline
(n, k) = list(map(int, input().split()))
import math
par = 0
for i in range(1, n + 1):
	tmp = i
	cnt = 0
	while True:
		if tmp >= k:
			break
		tmp *= 2
		cnt += 1
	if cnt == 0:
		par += 1 / n
	else:
		par += 1 / (2 ** cnt * n)
print(f'{par:.12f}')


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


(N, K) = map(int, input().split())
s = 0.0
for i in range(1, N + 1):
	c = 0
	while i * pow(2, c) < K:
		c = c + 1
	s = s + 1 / N * pow(1 / 2, c)
print(s)


import math
e = 0
(n, k) = map(int, input().split())
for i in range(1, n + 1):
	m = math.ceil(math.log2(k / i))
	e += 1 * (m < 1) or 2 ** (-m)
print(e / n)


(n, k) = map(int, input().split())
a = []
for i in range(1, n + 1):
	x = i
	b = 0
	while x < k:
		x = x * 2
		b += 1
	a.append(float(1 / n) * 0.5 ** b)
print(sum(a))


(N, K) = list(map(int, input().split()))
ans = 0
for i in range(N):
	a = i + 1
	b = 1
	while a < K:
		a = a * 2
		b = b * 0.5
	ans += b * 1 / N
print(ans)


(n, k) = list(map(int, input().split()))
ans = 0
from math import ceil, log2
for i in range(1, n + 1):
	if i < k:
		a = ceil(log2(k / i))
		ans += 1 / n * (1 / 2) ** a
	else:
		ans += 1 / n
print(ans)


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


(N, K) = map(int, input().split())
out = 0
for s in range(1, N + 1):
	j = 1 / N
	while s < K:
		s *= 2
		j /= 2
	out += j
print(out)


import math
(n, k) = map(int, input().split())
log2 = math.log10(2)
ans = 0
for i in range(1, n + 1):
	temp = i
	num = 1 / n
	while temp < k:
		num /= 2
		temp *= 2
	ans += num
print(ans)


(N, K) = list(map(int, input().split()))
A = 1
ans = 0
while A <= N:
	count = 0
	T = A
	while T < K:
		T = T * 2
		count += 1
	ans += float(1 / N * (1 / 2) ** count)
	A += 1
print(ans)


(N, K) = map(int, input().split())
p = 0
for i in range(1, N + 1):
	b = len(bin(int(K - 1) // i)) - 2
	if i >= K:
		b = 0
	p += 1 / (2 ** b * N)
print(p)


import math
(N, K) = map(int, input().split())
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(K / i, 2))
print(P)


from math import log2, ceil
(N, K) = list(map(int, input().split()))
ans = 0
j = 1.0
for x in range(N, 0, -1):
	if x >= K:
		ans += 1.0 * (1 / N)
	else:
		while x * j < K:
			j *= 2.0
		ans += 1.0 / j * (1 / N)
print(ans)


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


(n, k) = map(int, input().split())
p = 0
for score in range(1, n + 1):
	q = 1 / n
	count = 0
	while score < k:
		q = q / 2
		score = score * 2
	p = p + q
print(p)


def p(n, k):
	if n >= k:
		return 1
	num = 0
	while n < k:
		n *= 2
		num += 1
	return 1 / 2 ** num
(N, K) = map(int, input().split())
ans = 0
for n in range(1, N + 1):
	ans += p(n, K)
ans /= N
print(ans)


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


(N, K) = map(int, input().split())
ans = 0
for n in range(1, N + 1):
	p = 0
	while n * 2 ** p < K:
		p += 1
	ans += 0.5 ** p / N
print('{:.12f}'.format(ans))


import math
(N, K) = map(int, input().split())
ans = 0
for i in range(1, N + 1):
	if K // i != 0:
		a = math.log2(K / i)
		if a.is_integer():
			x = int(a)
		else:
			x = int(a) + 1
		ans += 1 / N * (1 / 2) ** x
	else:
		ans += 1 / N
print(ans)


from math import *
(n, k) = map(int, input().split())
ans = 0
for i in range(1, n + 1):
	tmp = 1 / n
	if i < k:
		tmp *= 0.5 ** ceil(log2(k / i))
	ans += tmp
print(ans)


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


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


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


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


(n, k) = [int(x) for x in input().split()]
ans = 0
for i in range(n):
	a = 1 / n
	now = i + 1
	while now < k:
		now *= 2
		a /= 2
	ans += a
print(ans)


(n, k) = map(int, input().split())
per = 0
for i in range(1, n + 1):
	a = 0
	while i < k:
		a += 1
		i *= 2
	per += 1 / n * 0.5 ** a
print(per)


(N, K) = map(int, input().split())
pro = 0.0
for i in range(1, N + 1):
	n = i
	j = 0
	while True:
		if n >= K:
			break
		n = n * 2
		j = j + 1
	pro = pro + 1 / N * 0.5 ** j
print(pro)


(n, k) = map(int, input().split())
ans = max(n - k + 1, 0)
(a, b, c) = (k, k, 1)
while a != 1:
	b = a + 1 >> 1
	ans += (min(a, n + 1) - min(b, n + 1)) / 2 ** c
	c += 1
	a = b
print(ans / n)


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


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


import sys

def solve(N: int, K: int):
	ans = 0
	for n in range(1, N + 1):
		b = 1
		while n * b < K:
			b <<= 1
		ans += 1 / (b * N)
	return ans

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	K = int(next(tokens))
	print(solve(N, K))

def test():
	import doctest
	doctest.testmod()

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
result = 0
for i in range(1, N + 1):
	prob = 1
	count = i
	while count < K:
		prob *= 0.5
		count *= 2
	result += prob / N
print(result)


def main():
	(N, K) = list(map(int, input().split()))
	ans = 0.0
	for i in range(1, N + 1):
		(j, k) = (i, 0)
		while j < K:
			j *= 2
			k += 1
		ans += pow(0.5, k) / N
	print(ans)

def __starting_point():
	main()
__starting_point()


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


(N, K) = [int(n) for n in input().split()]
ans = 0
for n in range(1, N + 1):
	tmp = 1.0 / N
	now = n
	while now < K:
		now *= 2
		tmp /= 2
	ans += tmp
print('{:.12}'.format(ans))


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


w = input().strip().split()
N = int(w[0])
K = int(w[1])
s = 0
for i in range(N):
	j = i + 1
	a = 1
	while j <= K - 1:
		j *= 2
		a *= 0.5
	s += a / N
print(s)


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


import math
(N, K) = list(map(int, input().split()))
ans = 0
for n in range(1, N + 1):
	if n >= K:
		ans += 1 / N
		continue
	x = math.ceil(math.log2(K / n))
	ans += 0.5 ** x / N
print(ans)


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


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


(n, k) = map(int, input().split())
sum: float = 0.0
for i in range(1, n + 1):
	ret: float = 1 / n
	tmp = i
	while tmp < k:
		tmp *= 2
		ret /= 2
	if tmp != 0:
		sum += ret
print(sum)


import math
(N, K) = map(int, input().split())
ans = 0
for i in range(1, N + 1):
	if i <= K - 1:
		ans += 1 / N * (1 / 2) ** math.ceil(math.log2(K / i))
	else:
		ans += 1 / N
print(ans)


r = input().split()
N = int(r[0])
K = int(r[1])
ans = 0
for i in range(1, N + 1):
	x = i
	n = 0
	while x <= K - 1:
		x = x * 2
		n += 1
	ans += 1 / N * (1 / 2) ** n
print(ans)


import math
(N, K) = map(int, input().split())
print(sum(map(lambda x: 0.5 ** max(0.0, math.ceil(math.log(K / x, 2))), range(1, N + 1))) / float(N))


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

def func1(i, k):
	ans = 0
	num = i
	end = False
	if num >= k:
		return 0
	while not end:
		ans += 1
		num *= 2
		if num >= k:
			end = True
			break
	return ans
ans = 0
for initial_score in range(1, N + 1):
	ans += 1 / N * (1 / 2) ** func1(initial_score, K)
print(ans)


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


import sys
(N, K) = map(int, sys.stdin.readline().split())
ans = 0
for i in range(1, N + 1):
	if K <= i:
		ans += 1 / N
	else:
		count = 0
		while i < K:
			count += 1
			i *= 2
		ans += 1 / N * 0.5 ** count
print(ans)


(N, k) = map(int, input().split())
ans = 0
coin = 0
for i in range(N, 0, -1):
	while 2 ** coin < k / i:
		coin += 1
	ans += 0.5 ** coin
print(ans / N)


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


(n, k) = map(int, input().split())
p = 0
for i in range(1, n + 1):
	p += [1, 4 / 2 ** len(bin(~-k // i))][i < k]
print(p / n)


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


(n, k) = map(int, input().split())
prob = [0] * n
for i in range(1, n + 1):
	j = 0
	while i * 2 ** j < k:
		j += 1
	prob[i - 1] = 1 / n * (1 / 2) ** j
print(sum(prob))


import math
(N, K) = [int(s) for s in input().split()]
a = 0
for i in range(N):
	a += 2 ** (-max([0, math.ceil(math.log2(K / (i + 1)))]))
print(a / N)


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


(n, k) = map(int, input().split())
p = 0
for i in range(1, n + 1):
	s = 0
	x = i * 2 ** s
	while x < k:
		s += 1
		x = i * 2 ** s
		p += 1 / n * (1 / 2) ** s
print(1 - p)


import math
(N, K) = [int(x) for x in input().split()]
S = 0
for i in range(1, N + 1):
	a = 0
	while i < K:
		a += 1
		i *= 2
	S += 0.5 ** a
ans = S / N
print(ans)


(n, k) = map(int, input().split())
x = 0
for i in range(1, n + 1):
	t = 0
	while i * 2 ** t < k:
		t += 1
	x += 2 ** (-t) / n
print(x)


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


import math
(n, k) = map(int, input().split())
s = 0
ans = 0
for x in range(1, n + 1):
	if x >= k:
		a = 0
	else:
		a = math.ceil(math.log2(k / x))
	b = 1 / n * 0.5 ** a
	ans += b
print(ans)


(n, k) = map(int, input().split())
p = float(0.0)
for i in range(1, n + 1):
	howmany = 0
	while i < k:
		i *= 2
		howmany += 1
	p += 1 / (n * 2 ** howmany)
print(p)


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


import math
(n, k) = map(int, input().split())
ans = 0
if n < k:
	for j in range(1, n + 1):
		a = math.ceil(math.log(k / j, 2))
		ans += 1 / n * (1 / 2 ** a)
	print(ans)
else:
	for j in range(1, k):
		a = a = math.ceil(math.log(k / j, 2))
		ans += 1 / n * (1 / 2 ** a)
	ans += (n - k + 1) / n
	print(ans)


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


def mapt(fn, *args):
	return tuple(map(fn, *args))

def Input():
	return mapt(int, input().split(' '))

def func(i, k):
	count = 0
	while i < k:
		i *= 2
		count += 1
	return count

def main():
	(n, k) = Input()
	ans = 0
	for i in range(1, n + 1):
		ans += 1 / n * (1 / 2 ** func(i, k))
	print(ans)
main()


(n, k) = map(int, input().split())
a = 0
for i in range(n):
	x = i + 1
	y = 0
	while x < k:
		x *= 2
		y += 1
	a += 1 / 2 ** y
print(a / n)


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


(n, k) = map(int, input().split())
sm = 0
s = 1 / n
for i in range(1, n + 1):
	x = i
	j = 0
	while x < k:
		x *= 2
		j += 1
	sm += s * 0.5 ** j
print(sm)


import math
(N, K) = map(int, input().split())
print(1 / N * sum([1 / pow(2, math.ceil(math.log2(max(K / i, 1)))) for i in range(1, N + 1)]))


INT = lambda : int(input())
INTM = lambda : map(int, input().split())
STRM = lambda : map(str, input().split())
STR = lambda : str(input())
LIST = lambda : list(map(int, input().split()))
LISTS = lambda : list(map(str, input().split()))

def do():
	(n, k) = INTM()
	ans = 0
	for i in range(1, n + 1):
		temp = i
		ct = 0
		while temp < k:
			ct += 1
			temp *= 2
		ans += 1 / (n * 2 ** ct)
	print(ans)

def __starting_point():
	do()
__starting_point()


(N, K) = map(int, input().split())
P = [0] * N
for i in range(N):
	s = i + 1
	k = 0
	while s < K:
		s *= 2
		k += 1
	P[i] = 1 / N * (1 / 2) ** k
print(sum(P))


(N, K) = list(map(int, input().split()))
ans = 0
for i in range(N):
	temp = K / (i + 1)
	for j in range(100):
		if 2 ** j >= temp:
			break
	ans += 1 / N * (1 / 2) ** j
print(ans)


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


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


(N, K) = map(int, input().split())
ans = max(0, (N - K + 1) / N)
for dice in range(1, min(N, K - 1) + 1):
	for time in range(1, len(bin(K)) + 2):
		dice *= 2
		if dice >= K:
			ans += 1 / (N * 2 ** time)
			break
print(ans)


(N, K) = map(int, input().split())
n = 1
p = 0.0
while n <= N:
	n2 = n
	p2 = 1.0
	while n2 < K:
		n2 *= 2
		p2 /= 2
	p += p2 / N
	n += 1
print(p)


(N, K) = map(int, input().split(' '))
j = 0
i = 1
while i <= N:
	s = 1
	while i * s < K:
		s *= 2
	j += 1 / s
	i += 1
print(j / N)


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


(N, K) = map(int, input().split())
p = 0
q = 0
for j in range(N, 0, -1):
	while j * 2 ** q < K:
		q += 1
	p += 0.5 ** q
print(p * (1 / N))


import math
(N, K) = map(int, input().split())
if K == 1:
	print(1)
	return
ans = 0
for i in range(1, N + 1):
	if i >= K:
		ans += 1 / N
	else:
		temp = math.log(K / i, 2)
		nu = pow(2, math.ceil(temp))
		ans += 1 / (nu * N)
print(ans)


from math import ceil, log2
(N, K) = map(int, input().split())
print(sum((1 if i >= K else 1 / 2 ** ceil(log2(K / i)) for i in range(1, N + 1))) / N)


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


def LI():
	return list(map(int, input().split()))
(N, K) = LI()
ans = 0
for i in range(1, N + 1):
	x = 1
	count = i
	while count < K:
		count *= 2
		x /= 2
	ans += x / N
print(ans)


(n, k) = map(int, input().split())
ans = 0
s = 1 / 2
while k > 1:
	ans += s * min(n, k - 1)
	k -= k // 2
	s /= 2
ans /= n
print(1 - ans)


(N, K) = map(int, input().split())
ans = 0.0
for i in range(N):
	X = 0
	Y = i + 1
	while Y < K:
		Y *= 2
		X += 1
	ans += 0.5 ** X
print(ans / N)


(n, k) = map(int, input().split())
ans = 0
for i in range(1, n + 1):
	j = i
	cnt = 1
	while j < k:
		j <<= 1
		cnt /= 2
	ans += cnt / n
print('{:10}'.format(ans))


from math import log2
import decimal
(N, K) = map(int, input().split())
decimal.getcontext().prec = 28
ans = decimal.Decimal(0)
for i in range(1, N + 1):
	if i < K:
		power = -(-(log2(K) - log2(i)) // 1)
		prob = decimal.Decimal(1 / (2 ** power * N))
	else:
		prob = decimal.Decimal(1 / N)
	ans = decimal.Decimal(ans + prob)
print(ans)


(n, k) = map(int, input().split())
print(sum(([1, 4 / 2 ** len(bin(~-k // i))][i < k] for i in range(1, n + 1))) / n)


def main():
	(N, K) = list(map(int, input().split()))
	ans = 0
	dict = {}
	cnt = 0
	tmp = 1 / N
	for i in range(N, 0, -1):
		i = float(i)
		if K <= i:
			ans += tmp * 0.5 ** cnt
		else:
			while True:
				K = K / 2
				cnt += 1
				if K <= i:
					break
			ans += tmp * 0.5 ** cnt
	return ans
print(main())


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


def main():
	(n, k) = list(map(int, input().split()))
	ans = 0.0
	for t in range(1, n + 1):
		cnt = 0
		now = t
		per = 1.0
		while now < k:
			per /= 2
			now *= 2
		ans += per / n
	print('{:.20}'.format(ans))
	pass

def __starting_point():
	main()
__starting_point()


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


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


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


from math import log2, ceil
(N, K) = map(int, input().split())
print('{:.12f}'.format(sum((min(1, 1 / 2 ** ceil(log2(K / i))) for i in range(1, N + 1))) / N))


import math
(n, k) = map(int, input().split())
p = 0
for i in range(1, n + 1):
	temp = 1
	while i * temp < k:
		temp *= 2
	p += 1 / temp
print(p / n)


(N, K) = map(int, input().split())
sum = 0.0
for a in range(1, N + 1):
	i = a
	b = 1.0
	while i < K:
		i = i * 2
		b = b / 2
	sum += b
print(sum / N)


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


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