Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well.

The last time in Byteland, Chef defeated the magician in his challenge and won a gold coin.

The magician does not want to give up his coin so easily, so he gives Chef $N$ coins. One of them is real and the remaining $N-1$ are fake; all fake coins have equal weights, different from the weight of the real coin. The coins are otherwise indistinguishable.

Chef has to find the real coin by himself. To make it fair, the magician gives Chef a balance. The balance is magical — it stays balanced when the sums of weights of coins put on each side are equal, but if they are not equal, the balance tilts to a random side instead of the side with the greater sum of weights. Chef can only use this balance up to $K$ times; if he cannot uniquely determine which coin is the real one afterwards, he has to guess the real coin (he may make a guess in any way he wants).

If Chef uses the balance optimally, what is the minimum possible probability that he will correctly determine the real coin at the end? We are interested in the worst-case scenario where the position of the gold coin is fixed initially (but unknown to Chef).

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $N$ and $K$.

------  Output ------
For each test case, print a single line containing one integer — the minimum probability that Chef will find the gold coin. Your output will be considered correct if its absolute error does not exceed $ 10^{-6}$.

------  Constraints  ------
$1 ≤ T ≤ 2 \cdot 10^{5}$
$1 ≤ N ≤ 10^{18}$
$0 ≤ K ≤ 10^{9}$

------  Subtasks ------
Subtask #1 (25 points): $1 ≤ N ≤ 10^{5}$

Subtask #2 (75 points): original constraints

----- Sample Input 1 ------ 
4
3 1
3 2
4 1
1 5
----- Sample Output 1 ------ 
0.500000
1.000000
0.500000
1.000000
----- explanation 1 ------ 
Example case 1: Chef takes two coins and puts them on the two sides of the balance. If the balance tilts, then one of these two coins is real. (Otherwise, they are both fake and Chef found the real coin; we do not consider this scenario, since it does not lead to the minimum probability.) Chef cannot use the balance any more, so he cannot determine which of these two coins is the real one. He has to guess one; this guess is correct with probability $1/2$.

Example case 2: The first use of the balance is the same as before. If the balance does not tilt, he knows the real coin. Otherwise, Chef replaces one coin on the balance. If the balance tilts again, the coin that was not replaced is the real one. Otherwise, the replaced coin is the real one.

Difficulty: HARD

Solutions:
import math
t = int(input())
for x in range(t):
	(n, k) = map(int, input().split())
	if n == 1:
		print(str.format('{0:.6f}', 1))
		continue
	if k == 0:
		print(str.format('{0:.6f}', 1 / n))
		continue
	if n == 2:
		print(str.format('{0:.6f}', 1 / 2))
		continue
	l = math.ceil(math.log2(n))
	if k >= l:
		print(str.format('{0:.6f}', 1))
		continue
	elif k == 1:
		a = math.ceil(n / 2)
		if a % 2 == 1:
			if a + a == n:
				a = a + 1
		print(str.format('{0:.6f}', 1 / a))
		continue
	else:
		m = math.ceil(n / 2 ** k)
		print(str.format('{0:.6f}', 1 / m))


def getminp(n, k):
	if n == 1:
		return 1.0
	if n == 2:
		return 0.5
	looped = False
	while k:
		if n == 1 or n == 2:
			return 1
		if n % 4 == 0:
			n //= 2
		elif n % 2 == 0 and looped:
			n = n // 2
		else:
			n = n // 2 + 1
		k -= 1
		looped = True
	return 1 / n
for _ in range(int(input())):
	i = list(map(int, input().split()))
	print(str.format('{0:.6f}', getminp(i[0], i[1])))


def hell(n, k):
	if n == 0:
		return 1
	if k == 0 or n == 1:
		return n
	val = int(n / 2)
	if n % 2:
		val += 1
	return hell(val, k - 1)
for _ in range(int(input())):
	i = list(map(int, input().split()))
	if i[0] % 2 == 0 and i[1] == 1 and (i[0] / 2 % 2 != 0):
		a = 1 / (int(i[0] / 2) + 1)
	elif i[0] > 2:
		a = 1 / hell(i[0], i[1])
	else:
		a = 1 / i[0]
	print(str.format('{0:.6f}', a))


def main():
	t = int(input())
	for i in range(t):
		s = input().split()
		n = int(s[0])
		k = int(s[1])
		if n == 1:
			print('1.000000')
		elif n == 2:
			print('0.500000')
		elif k > 64:
			print('1.000000')
		elif k == 1:
			if n % 2 == 1:
				n = int(n / 2) + 1
			else:
				n = int(n / 2)
				if n % 2 != 0:
					n = n + 1
			print('%.6f' % (1 / n))
		else:
			for i in range(k):
				if n == 1:
					break
				n = max(int(n / 2), int((n + 1) / 2))
			print('%.6f' % (1 / n))
main()


from math import ceil

def chek(number_of_coin, k_balance):
	if k_balance == 0:
		print('{0:.6f}'.format(1 / number_of_coin))
	elif number_of_coin == 1:
		print('{0:.6f}'.format(1))
	elif number_of_coin == 2:
		print('{0:.6f}'.format(1 / 2))
	else:
		if k_balance > 0 and number_of_coin % 2 == 0 and (int(number_of_coin / 2) % 2 != 0):
			number_of_coin = ceil(number_of_coin / 2) + 1
			k_balance -= 1
		while k_balance > 0 and number_of_coin > 1:
			number_of_coin = ceil(number_of_coin / 2)
			k_balance -= 1
		if k_balance == 0:
			print('{0:.6f}'.format(1 / number_of_coin))
		elif number_of_coin == 1:
			print('{0:.6f}'.format(1))
for _ in range(int(input())):
	(number_of_coin, k_balance) = [int(x) for x in input().split()]
	chek(number_of_coin, k_balance)


def f1(n):
	print(n, ':')
	if n < 3:
		print('{0:.6f}'.format(1 / n))
		return None
	k = 0
	print(k, ':', '{0:.6f}'.format(1 / n), ';', n)
	k += 1
	n = n // 4 * 2 + min(n % 4, 2)
	while n > 1:
		print(k, ':', '{0:.6f}'.format(1 / n), ';', n)
		n = n // 2 + n % 2
		k += 1
	if n == 1 and k > 0:
		print(k, ':', '{0:.6f}'.format(1 / n))
	else:
		print('error')
	return None

def f(n, k):
	if n < 3:
		return n
	if k > 0:
		n = n // 4 * 2 + min(n % 4, 2)
		k -= 1
	while k > 0 and n > 1:
		n = n // 2 + n % 2
		k -= 1
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print('{0:.6f}'.format(1 / f(n, k)))


import math as m

def main(n, k):
	if k == 0:
		return 1 / n
	if n == 1:
		return 1.0
	if n == 2 and k >= 1 or (n == 3 and k > 1):
		return 1.0
	else:
		num1 = n // 2
		num2 = n - num1
		return main(max(num1, num2), k - 1)
t = int(input())
for i in range(0, t):
	n_k = input().split(' ')
	n = int(n_k[0])
	k = int(n_k[1])
	if k == 0:
		print(str.format('{0:.7f}', 1 / n)[:8])
	elif n == 2:
		print('0.500000')
	elif n == 3 and k == 2:
		print(str.format('{0:.7f}', 1)[:8])
	else:
		num1 = n // 2
		if num1 % 2 == 0:
			num2 = n - num1
		if num1 % 2 != 0 and n % 2 != 0:
			num2 = n - num1
		elif num1 % 2 != 0 and n % 2 == 0:
			num1 = num1 - 1
			num2 = n - num1
		print(str.format('{0:.7f}', main(max(num1, num2), k - 1))[:8])


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	p = k
	if n == 1 or n == 2:
		pass
	else:
		while k:
			if n == 2:
				n = 1
				break
			if n % 2 == 0:
				n = n // 2
				if n % 2 == 1 and p == k:
					n += 1
			else:
				n = math.ceil(n / 2)
			k -= 1
	print('%.6f' % (1 / n))


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k == 0:
		n = n
	elif n == 2:
		n = 2
	elif k > n // 2 or n == 1:
		n = 1.0
	elif k == 1 and n // 2 % 2 == 0:
		x1 = n // 2
		x2 = n - x1
		n = max(x1, x2)
	elif k == 1 and n // 2 % 2 != 0:
		n = n // 2 + 1
	else:
		while k > 0 and n > 1:
			n = math.ceil(n / 2)
			k -= 1
	prob = 1.0 / n
	print('{0:.6f}'.format(prob))


def solve(N, K):
	if K == 0:
		return 1 / N
	if N == 1:
		return 1.0
	if N == 2:
		return 0.5
	if N % 4 == 0:
		N = N // 2
	elif N % 4 == 1:
		N = N // 2 + 1
	elif N % 4 == 2:
		N = N // 2 + 1
	else:
		N = 2 * (N // 4) + 2
	K -= 1
	while K > 0 and N >= 2:
		N = N // 2 + N % 2
		K -= 1
	if K == 0:
		return 1 / N
	return 1.0
T = int(input())
for i in range(0, T):
	(N, K) = [int(s) for s in input().split(' ') if s != '']
	print('%.6f' % solve(N, K))


t = int(input())
while t:
	(n, k) = map(int, input().split())
	flag = True
	result = 0
	while flag:
		x = 0
		if n <= 1:
			flag = False
			print(str.format('{0:.6f}', 1))
		if k == 0 and flag != False:
			flag = False
			print(str.format('{0:.6f}', 1 / n))
		if n % 2 != 0 or result > 0:
			x = (n + 1) // 2
		else:
			mid = n // 2
			if mid % 2 == 0:
				x = mid
			else:
				x = mid + 1
		result = result + n - x
		n = x
		k -= 1
	t -= 1


tc = int(input())
for t in range(tc):
	(n, k) = [int(temp) for temp in input().split()]
	ans = n
	if ans == 2:
		dan = 1 / ans
		print('%.6f' % dan)
		continue
	for i in range(1, k + 1):
		if ans == 1:
			break
		if i == 1:
			if ans % 2 == 0:
				ans = ans // 2
				if ans % 2 != 0:
					ans = ans + 1
			else:
				ans = ans // 2 + 1
		elif ans % 2 == 0:
			ans = ans // 2
		else:
			ans = ans // 2 + 1
	dan = 1 / ans
	print('%.6f' % dan)


def fun(n, k):
	if n == 1:
		return 1
	if k == 0:
		return 1 / n
	if k == 1:
		return 1 / (n // 2 + n % 2)
	return fun(n // 2 + n % 2, k - 1)
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	use = fun(n, k)
	if n == 2:
		use = 0.5
	if k == 1:
		use = 1 / (n // 2 + n % 2 + n // 2 % 2 * (1 - n % 2))
	print('%.6f' % use)


from math import floor
from math import ceil

def g(n):
	if n % 4 == 0:
		return 2 * floor(n / 4)
	if n % 4 == 1:
		return 2 * floor(n / 4) + 1
	else:
		return 2 * floor(n / 4) + 2

def f(n, k):
	if n == 1:
		return 1
	if n == 2:
		return 0.5
	if k == 0:
		return 1 / n
	n = g(n)
	k = k - 1
	while n > 1 and k > 0:
		n = ceil(n / 2)
		k = k - 1
	return 1 / n
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print('{0:.6f}'.format(f(n, k)))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 0:
		print('%.6f' % (1.0 / n))
		continue
	if n == 2:
		print('%.6f' % 0.5)
		continue
	if n % 4 == 2:
		n = n // 2 + 1
	else:
		n = (n + 1) // 2
	k -= 1
	for i in range(k):
		n = (n + 1) // 2
		if n < 2:
			break
	if n < 2:
		print('%.6f' % 1.0)
	else:
		print('%.6f' % (1.0 / n))