Kevinsogo is a professor of mathematics, One day he gave an assignment to his students which was hard for them. The students want you to help them in solving the problem.

Given the value of $N$, 

$x=\text{rand()}\bmod N$ 

$Y=\sqrt{x+\sqrt{x+\sqrt{x+\sqrt{x+\cdots}}}}$

Note that $\text{rand}()$ returns an integer between ${0}$ and $10^{100}$ (inclusive) uniformly at random.

Find out the expected value of ${Y}$.

Input Format 

The first line contains an integer ${T}$ i.e. the number of test cases.

The next ${T}$ lines will each contain an integer $N$.

Output Format 

Print the output corresponding to each test case in a separate line. The answer will be considered correct if its absolute error doesn't exceed $10^{-3}$ or ${0.001}$.  

Constraints 

Task 1: 30 points 

$1\leq T\leq10000$ 

$1\leq N\leq5\times10^6$  

Task 2: 10 additional points 

$1\leq T\leq1000$ 

$1\leq N\leq10^{16}$  

Sample Input

3
1
5
10

Sample Output

0.0
1.69647248786
2.43798952788

Difficulty: MEDIUM
Tags: Probability

Starter code:

Solutions:
from math import sqrt
M = 5000500
a = [0.5 * (1 + sqrt(1 + 4 * i)) for i in range(M)]
a[0] = 0
for i in range(1, M):
	a[i] += a[i - 1]
t = int(input())

def fairAnswer(n):
	return a[n - 1] / n

def unfairAnswer(n):
	return (0.5 * (n - 1) + 2 / 3 * (0.25 + n - 1) ** 1.5) / n
for i in range(t):
	n = int(input())
	if n < M:
		print(fairAnswer(n))
	else:
		print(unfairAnswer(n))


err = 2235.023971557617
N = 5 * 10 ** 6
pref = [0]
for i in range(1, 5 * 10 ** 6):
	pref.append(pref[-1] + (1 + (4 * i + 1) ** 0.5) * 0.5)
t = int(input())
for _ in range(t):
	n = int(input())
	if n < N:
		print(pref[n - 1] / n)
	else:
		sum = (4 * (n - 1) + 5) ** 1.5 / 6 - 5 ** 1.5 / 6 - err
		ans = 0.5 + sum / (2 * n)
		print(ans)


import math

def main():
	numCases = int(input())
	cases = []
	for i in range(0, numCases):
		cases.append([int(input()), i])
	cases.sort(key=lambda x: x[0])
	previousCase = 1
	previousSum = 0
	for pair in cases:
		n = pair[0]
		if n < 500000:
			if n > 0:
				sumExpectedValue = sum(map(lambda k: 1.0 / 2.0 + math.sqrt(1.0 + 4.0 * k) / 2.0, range(previousCase, n)))
				sumExpectedValue += previousSum
				previousCase = n
				previousSum = sumExpectedValue
			else:
				sumExpectedValue = 0
			sumExpectedValue = sumExpectedValue / (1.0 * n)
			pair[0] = sumExpectedValue
		else:
			intExpectedValue = (n - 1) / 2.0 + 1.0 / 12.0 * (1 + 4 * (n - 1)) ** (3.0 / 2.0) - 1.0 / 12.0
			intExpectedValue = intExpectedValue / (1.0 * n)
			pair[0] = intExpectedValue
	cases.sort(key=lambda x: x[1])
	for pair in cases:
		print(pair[0])
main()


from math import sqrt
M = 5000500
a = [0.5 * (1 + sqrt(1 + 4 * i)) for i in range(M)]
a[0] = 0
for i in range(1, M):
	a[i] += a[i - 1]
t = int(input())

def fairAnswer(n):
	return a[n - 1] / n

def unfairAnswer(n):
	return (0.5 * (n - 1) + 2 / 3 * (0.25 + n - 1) ** 1.5) / n
for i in range(t):
	n = int(input())
	if n < M:
		print(fairAnswer(n))
	else:
		print(unfairAnswer(n))


__author__ = 'burakks41'
from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


from math import sqrt
A = []
A[0:3] = [0, 0, sqrt(5)]
for k in range(3, 219):
	A.append(A[k - 1] + sqrt(1 + 4 * (k - 1)))
T = int(input())
for _ in range(T):
	N = int(input())
	ans = (N - 1) / (2 * N)
	if N < 219:
		ans += A[N] / (2 * N)
	else:
		ans += ((4 * N - 1) ** (3 / 2) - 3 ** (3 / 2)) / (12 * N)
	print(ans)


from math import sqrt
for _ in range(int(input())):
	N = int(input())
	if N < 10000:
		print((1 + sum((sqrt(1 + 4 * x) for x in range(N))) / N) / 2 - 1 / N)
	else:
		print(1 / 2 + sqrt(4 * N - 2) / 3)


from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


nTst = int(input())
for i in range(nTst):
	nn = int(input())
	s1 = 0
	if nn == 1:
		s1 = 0
	elif nn < 3000:
		for i1 in range(1, nn):
			s1 = s1 + pow(0.25 + i1, 0.5)
		s1 = 0.5 + (s1 - 0.5) / nn
	else:
		s1 = 0.5 + ((3 * pow(4 * nn + 1, 0.5) - 3 * pow(4 * nn - 3, 0.5) - 4) / 12 - 0.5) / nn + pow(4 * nn - 3, 0.5) / 3
	print(s1)


import math

def ev(n):
	if n <= 1000000:
		return (sqval[n - 1] + n - 1) / (2 * n)
	c = 4 * (n - 1)
	tot = ((1 + c) * math.sqrt(1 + c) - 1) * 2 / (3 * c)
	return (1 + tot) * (0.5 - 1 / (2 * n))
sqval = [0]
tot = 0
for i in range(1, 1000000):
	tot += math.sqrt(1 + 4 * i)
	sqval.append(tot)
T = int(input().strip())
for _ in range(T):
	n = int(input().strip())
	print(ev(n))


def f(n):
	y = 0
	for i in range(n):
		y = y + (i + 0.25) ** 0.5
	return (y - 1) / n + 0.5

def g(n):
	y = 2 / 3 * (n + 0.25) ** 0.5 + 0.5
	return y - 48.05012981961454 / n

def noprob(n):
	if n < 20000:
		y = f(n)
	else:
		y = g(n)
	return y
T = int(input())
X = []
for i in range(T):
	X.append(int(input()))
Y = map(noprob, X)
for y in Y:
	print('{:.30f}'.format(y))


from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


import math
T = int(input())
ss = [0, 0]
for i in range(1, 10 ** 7):
	y = (1.0 + math.sqrt(1 + 4 * i)) / 2.0
	ss.append(ss[-1] + y)

def int_get(a, b):
	return (b - a) / 2.0 + 1.0 / 12.0 * ((1.0 + 4.0 * b) ** 1.5 - (1.0 + 4.0 * a) ** 1.5)
for i in range(T):
	n = int(input())
	if n < len(ss):
		q = ss[n]
	else:
		q = ss[-1] + int_get(len(ss), n)
	print(q / n)


from math import sqrt
max_n = 10 ** 6

def f(x):
	return 0.5 * (1 + (1 + 4 * x) ** 0.5)

def int_f(x):
	return 0.5 * ((1 + 4 * x) ** 1.5 / 6 + x)
table = [0]
for i in range(1, max_n):
	table.append(table[i - 1] + f(i))
for _ in range(int(input())):
	x = int(input())
	if x <= max_n:
		print(table[x - 1] / x)
	else:
		print((int_f(x) - int_f(1)) / x)


v = [0]
for i in range(1, 5000000):
	v.append(v[-1] + (1 + 4 * i) ** 0.5)
print('\n'.join(map(lambda x: str(0.5 * (x - 1 + v[x - 1]) / x if x <= 5000000 else 0.5 + x ** 0.5 * 4 ** 1.5 / 12), (int(input()) for _ in range(int(input()))))))


from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


import functools
import math
T = int(input())

def isqrt(a, b):
	return ((1 + 4 * b) ** 1.5 - (1 + 4 * a) ** 1.5) / 6

def approx(N):
	i1 = isqrt(0, N - 1)
	i2 = isqrt(1, N)
	return (N - 1 + i1) / (2 * N)
Ns = [int(input()) for _ in range(T)]
large_N = [N for N in Ns if abs(isqrt(0, N - 1) - isqrt(1, N)) < 2 * N * 0.001]
small_N = [N for N in Ns if N not in large_N]
if small_N:
	cs = [0.0] * max(small_N)
	for n in range(1, max(small_N)):
		cs[n] = cs[n - 1] + math.sqrt(1 + 4 * n)
for N in Ns:
	if N in large_N:
		print(approx(N))
	else:
		print((N - 1 + cs[N - 1]) / (2 * N))


from math import sqrt, pi
cases = int(input().strip())
for _ in range(cases):
	n = int(input().strip())
	if n < 20000:
		arr = [sqrt(4 * x + 1) for x in range(1, n)]
		result = (sum(arr) + n - 1) / (2 * n)
	else:
		s = 4 / 3 * n * sqrt(n) + 3 / 2 * sqrt(n) + 1 / (24 * sqrt(n)) - 1 / 24 * (sqrt(n) + sqrt(n + 1)) ** (-5) / sqrt(n * (n + 1))
		result = (s + n - 1) / (2 * n) - 1 / sqrt(n)
	print(result)


from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


n = int(input())
Nall = []
for i in range(n):
	Nall.append(int(input().strip()))
b = sorted(range(len(Nall)), key=Nall.__getitem__)
sumsofar = 0
s = [0]
indstart = 1
op = [0 for i in range(0, n)]
for i in b:
	N = Nall[i]
	if N > 1000000.0 + 1000.0:
		op[i] = 0.5 + (1 + 4 * (N - 1)) ** 1.5 / 12 / N
	else:
		s.extend([1 + (1 + 4 * i) ** 0.5 for i in range(indstart, N)])
		sumsofar += sum(s)
		op[i] = sumsofar / N / 2
		indstart = N
		s = []
for i in range(0, n):
	print(op[i])


import math
lines = int(input())
for i in range(lines):
	N = int(input())
	if N < 10000:
		delta = -1
		for x in range(1, N):
			delta += math.sqrt(1 + 4 * x)
	else:
		delta = 1 / 6 * math.pow(1 + 4 * (N - 1), 3 / 2) + math.sqrt(1 + 4 * (N - 1)) / 2
	delta /= N
	print((1 + delta) / 2)


from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


from math import sqrt

def memoize(f):
	memo = {}

	def helper(x):
		if x not in memo:
			memo[x] = f(x)
		return memo[x]
	return helper

def y(x):
	return sqrt(x + 0.25)

@memoize
def partial_sum(N):
	if N == 0:
		return 0.0
	else:
		out = 0
		for n in range(1, N):
			out += sqrt(n + 0.25)
		return out

def large_n_partial_sum(N):
	zeta = -0.4096777412387538 - 1
	s = 0.5 + 2 / 3 * sqrt(N) - 0.25 / sqrt(N) + zeta / N - 1 / 192 * N ** (-3 / 2)
	return s

def expected_value(N):
	if N < 10 ** 4:
		return partial_sum(N) / N + (N - 1) / (2 * N)
	else:
		return large_n_partial_sum(N)
N = int(input())
for _ in range(N):
	n = int(input())
	print(expected_value(n))


xs = [0 for i in range(5000000)]
for i in range(1, 5000000):
	xs[i] = xs[i - 1] + (1 + (1 + 4 * i) ** 0.5) / 2
for _ in range(int(input())):
	k = int(input())
	if k <= 5000000.0:
		print(xs[k - 1] / k)
	else:
		k -= 1
		sumsq = 2 / 3 * k ** 1.5 + 0.5 * k ** 0.5 + k ** (-0.5) * (1 / 24 - 1 / (1920 * k ** 2) + 1 / (9216 * k ** 4))
		sumsq += k / 2
		print(sumsq / (k + 1))


import sys
import math
from itertools import accumulate
linha = sys.stdin.readline()
T = int(linha)
NN = []
for i in range(T):
	linha = sys.stdin.readline()
	N = int(linha)
	NN.append(N)
maxN = max(NN)
if maxN > 1000000:
	maxN = 1000000
y = [(math.sqrt(1 + 4 * x) + 1) / 2 for x in range(maxN)]
y[0] = 0
y = list(accumulate(y))
for i in range(T):
	if NN[i] < 1000000:
		print(y[NN[i] - 1] / NN[i])
	else:
		curr = NN[i]
		val = (curr + (math.pow(1 + 4 * curr, 1.5) - 1) / 6) / (2 * curr)
		print(val)


import math

def func(x):
	if x == 0:
		return 0
	return 0.5 + 0.5 * math.sqrt(1 + 4 * x)
T = int(input())
for cnt in range(T):
	N = int(input())
	if N > 10000:
		est = 0.5 + (0.5 * (1 + 4 * (N - 1)) ** 1.5 + 0.5 * (1 + 4 * N) ** 1.5 - 5 ** 1.5) / 12 / N
		print(est)
	else:
		outp = sum(map(func, range(1, N)))
		outp /= N
		print(outp)


from math import sqrt

def calc(n):
	if n == 1:
		return 0.0
	elif n <= Th:
		return (n - 1 + Tab[n - 1]) / 2 / n
	else:
		s = (n - 1) / 2 / n
		s += (-2 - 3 * sqrt(-3 + 4 * n) + sqrt(1 + 4 * n) + 4 * n * (sqrt(-3 + 4 * n) + sqrt(1 + 4 * n))) / (24 * n)
		return s
Th = 100000
Tab = [0] * Th
for i in range(1, Th):
	Tab[i] = Tab[i - 1] + sqrt(4 * i + 1)
T = int(input())
for _ in range(T):
	N = int(input())
	print(calc(N))


import sys
from time import time

def get_y(x):
	if x == 0:
		return 0
	return (1 + pow(1 + 4 * x, 0.5)) / 2

def solve_bf(n):
	sm = 0
	for i in range(n):
		sm += get_y(i)
	return sm / n

def integral_y(x):
	return x / 2 + 1 / 12 * pow(1 + 4 * x, 3 / 2)

def solve(n):
	if n < 10000:
		return solve_bf(n)
	return ((integral_y(n - 1) + integral_y(n)) / 2 - integral_y(1)) / n
tm = time()
t = int(input())
for _ in range(t):
	n = int(input())
	print(solve(n))
print('time elapsed: %s' % (time() - tm,), file=sys.stderr)


from math import sqrt
T = int(input())
for t in range(T):
	N = int(input())
	if N == 1:
		print(0.0)
	else:
		x = 4 * N - 3
		print(0.5 + (((x + 3) * x + 1) / 12 / sqrt(x) - 0.9096777412387537) / N)


from math import sqrt, fsum
eps = 0.001
maxln = 5 * 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


T = int(input())
from math import sqrt
precalc = [0]
s = 0
for x in range(1, int(5000000.0 + 1)):
	N = x + 1
	s = s + sqrt(1 + 4 * x)
	precalc.append(0.5 * (N - 1 + s) / N)
for i in range(T):
	N = int(input())
	if N <= 5000000.0:
		print(precalc[N - 1])
	else:
		print(sqrt(N) * 2 / 3.0 + 0.5)


import os
import sys

def solve(n):
	if n == 1:
		return 0
	ans = (n - 1) / (2 * n)
	c = -1.999867968
	t = (4 * n + 1 + c) ** 1.5
	t -= (5 + c) ** 1.5
	t /= 12 * n
	ans += t
	return ans

def solve2(n):
	if n == 1:
		return 0
	ans = 0
	for i in range(1, n):
		ans += 0.5 + (i + 0.25) ** 0.5
	ans /= n
	return ans
t = int(input())
for t_itr in range(t):
	n = int(input())
	if n > 10000:
		print(solve(n))
	else:
		print(solve2(n))


import os
import sys
from math import sqrt
max_n = 5 * 10 ** 6

def y(x):
	return (1 + sqrt(4 * x + 1)) / 2

def integral_y(x):
	return x / 2 + (4 * x + 1) ** 1.5 / 12
sol_list = [0]
for i in range(1, max_n):
	sol_list.append(sol_list[i - 1] + y(i))
for _ in range(int(input())):
	num = int(input())
	if num < max_n:
		print(sol_list[num - 1] / num)
	else:
		print((integral_y(num) - integral_y(1)) / num)


from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


__author__ = 'burakks41'
from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


__author__ = 'burakks41'
from math import sqrt, fsum
eps = 0.001
maxln = 10 ** 6

def f(val):
	return (1 + sqrt(4 * val + 1)) / 2

def interal_f(val):
	return val / 2 + (4 * val + 1) ** 1.5 / 12
solutionList = [0]
for i in range(1, maxln + 1):
	solutionList.append(solutionList[i - 1] + f(i))
for _ in range(int(input())):
	num = int(input())
	sol = 0
	if num <= maxln:
		sol = solutionList[num - 1] / num
	else:
		sol = (interal_f(num) - interal_f(1)) / num
	print(sol)


from math import sqrt
M = 5000500
a = [0.5 * (1 + sqrt(1 + 4 * i)) for i in range(M)]
a[0] = 0
for i in range(1, M):
	a[i] += a[i - 1]
t = int(input())

def fairAnswer(n):
	return a[n - 1] / n

def unfairAnswer(n):
	return (0.5 * (n - 1) + 2 / 3 * (0.25 + n - 1) ** 1.5) / n
for i in range(t):
	n = int(input())
	if n < M:
		print(fairAnswer(n))
	else:
		print(unfairAnswer(n))