IPL 2021 final is yet again between MI and CSK. It's already been two super overs
and the last bowl of the third super over is left. MS Dhoni hits the ball 
and it gets lofted high. You, being an MI fan, want MSD to get caught. 

There are infinite players in the stadium and any player will always catch the ball
within his area. The outermost player has an access to the whole ground which is a  $n$ sided regular polygon. 
New $n$ sided regular polygons are recursively formed by using the midpoints of the previous polygon as shown in the figure below,
where the area inside each polygon represents, the ground covered by a single player.  Now, assuming the ball is a point object which can land anywhere on the  ground (equal to the outermost $n$ sided regular polygon) 
with the same probability, what is the  expected number of players  who can take the catch?

Infinite regular polygons having number of sides $n = 4$. 

Formally, your task is to find the expected value of the number of polygons a randomly chosen point (within the outermost $n$ sided regular polygon) will be inside.  

------  Input  ------ 

The first line contains a single integer $T$, which denotes the number 
of test cases. The description of each test case follows. 
    
The first and the one line of each test case contains a positive 
integer $n$  - number of sides of the polygon
    
------  Output  ------ 

For each test case, print a single line containing one real number corresponding 
to the expected number of polygons the ball will be inside. Your answer 
will be considered correct if it has an absolute or relative error $≤ 10^{-6}$.

------ Constraints  ------ 

$ $1 ≤ T ≤ 10^{4}$ $
$ $3 ≤ n ≤ 10^{5}$ $

----- Sample Input 1 ------ 
2
3
4
----- Sample Output 1 ------ 
1.33333333
2.00000000

Source: codechef | Difficulty: HARD
Tags: Geometry

Mathematics

Probability


Solutions:
from math import sin, pi
T = int(input())
for ball in range(T):
	n = int(input())
	print(round((1 / sin(pi / n)) ** 2, 7))


import math
for _ in range(int(input())):
	n = int(input())
	a = math.pi * (n - 2) / (2 * n)
	print(1 / (1 - math.sin(a) ** 2))


import math
t = int(input())
while t:
	n = int(input())
	theta = math.pi - 2 * math.pi / n
	res = 1 / math.pow(math.cos(theta / 2), 2)
	print('{:.6f}'.format(res))
	t -= 1


import math
T = int(input())
while T:
	N = int(input())
	theta = math.pi - 2 * math.pi / N
	result = 1 / math.pow(math.cos(theta / 2), 2)
	print('{:.6f}'.format(result))
	T -= 1


import math
x = int(input())
for i in range(x):
	a = int(input())
	print(round(pow(1 / math.sin(math.pi / a), 2), 7))


from math import sin
from math import pi
for u in range(int(input())):
	n = int(input())
	y = sin(pi / n)
	print(1 / (y * y))


import math
t = int(input())
while t > 0:
	n = int(input())
	theta = math.pi - 2 * math.pi / n
	ans = 1 / math.pow(math.cos(theta / 2), 2)
	print('{:.6f}'.format(ans))
	t -= 1


from math import *
for I in range(int(input())):
	print('%.7f' % (1 / sin(pi / int(input())) ** 2))


import math

def main():
	for I in range(int(input())):
		n = int(input())
		angle = math.pi / n
		ratio = math.sin(angle)
		ratio *= ratio
		ans = 1 / ratio
		print('%.7f' % ans)
main()


import math
t = int(input())
for i in range(t):
	n = float(input())
	theta = math.pi - 2 * math.pi / n
	result = 1 / math.pow(math.cos(theta / 2), 2)
	print('{:.6f}'.format(result))


try:
	import math
	t = int(input())
	for i in range(0, t):
		n = int(input())
		a = math.pi / n
		b = math.sin(a)
		b = 1 / b
		k = pow(b, 2)
		print('{:.8f}'.format(k))
except:
	pass


import sys
import math as mt

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

def getInt():
	return int(getInput())

def getInts():
	return map(int, getInput().split())

def getArray():
	return list(getInts())
for _ in range(int(input())):
	n = int(input())
	print(1 / (mt.sin(mt.pi / n) * mt.sin(mt.pi / n)))


import math
for _ in range(int(input())):
	n = int(input())
	ans = (math.sin(math.pi / n) ** 2) ** (-1)
	print('%.8f' % ans)


from math import cos, pi
for _ in range(int(input())):
	n = int(input())
	p = cos(pi / n) ** 2
	z = 1 - p
	print('{0:.8f}'.format(1 / z))


import math
for _ in range(int(input())):
	n = int(input())
	r = math.cos(math.pi / n) ** 2
	x = 1 - r
	ans = 1 / x + r / x ** 2
	print(ans * x)


from math import cos, pi
for test in range(int(input())):
	n = int(input())
	v = pow(cos(pi / n), 2)
	print(1 / (1 - v))


from math import sin, tan, cos, pi

def probab(n):
	angle = (n - 2) * pi / (2 * n)
	h = tan(angle)
	base = 2
	area1 = 1 / 2 * base * h * n
	b2 = 2 * h * cos(angle)
	h2 = h * sin(angle)
	area2 = 1 / 2 * b2 * h2 * n
	ratio = area2 / area1
	print(1 / (1 - ratio))
for _ in range(int(input())):
	probab(int(input()))


from math import sin, pi, sqrt
cases = int(input())
for _ in range(cases):
	n = int(input())
	r = 1 / sin(pi / n) ** 2
	print('{:.8f}'.format(r))


from math import cos, pi

def answer(n):
	common_ratio = cos(pi / n) * cos(pi / n)
	return 1 / (1 - common_ratio)
for T in range(int(input())):
	n = int(input())
	print('%.8f' % answer(n))


import math
t = int(input())
while t > 0:
	n = int(input())
	k = 1 - math.sin(math.pi / 2 - math.pi / n) ** 2
	print(1 / k)
	t = t - 1


import math

def calll():
	n = int(input())
	pi = math.pi
	a = (n - 2) * 180 / n
	val = n * math.sin(a * pi / 180) / 8
	r = n / (4 * math.tan(pi / n))
	v = (r - val) / r
	print(1 / (1 - v))
for _ in range(int(input())):
	calll()


import math
for _ in range(int(input())):
	n = int(input())
	x = n * math.sin(math.pi * (n - 2) / n) / 8
	A = n / 4 / math.tan(math.pi / n)
	c = x / A
	print(round(1 / c, 6))


import math

def solve():
	n = int(input())
	pi = math.pi
	a = (n - 2) * 180 / n
	a1 = n * math.sin(a * pi / 180) / 8
	ratio = n / (4 * math.tan(pi / n))
	s = (ratio - a1) / ratio
	print(1 / (1 - s))
for _ in range(int(input())):
	solve()


import math
p = math.pi
T = int(input())
for t in range(T):
	n = int(input())
	ang = (n - 2) * 180 / n
	sm = (180 - ang) / 2
	ang = ang * (p / 180)
	sm = sm * (p / 180)
	a1 = n * math.tan(sm) / 4
	a2 = math.tan(ang / 2) * n / 4
	q = a2 / (a1 + a2)
	print(1 / (1 - q))


import math
for _ in range(int(input())):
	n = int(input())
	x = math.cos(math.pi / n)
	print(1 / (1 - math.pow(x, 2)))


import math
t = int(input())
PI = 3.141592653589793
for _ in range(t):
	n = int(input())
	angle = PI * (1 - 2 / n)
	sinangle = math.sin(angle / 2)
	sinsq = sinangle * sinangle
	ans = 1 / (1 - sinsq)
	print(ans)


import math

def solve(n):
	alpha = math.radians((n - 2) * 180 / n)
	ratio = (1 - math.cos(alpha)) / 2
	res = 1 / (1 - ratio)
	return res
t = int(input())
for i in range(t):
	n = int(input())
	print(solve(n))


import math
test_case = int(input())
for _ in range(test_case):
	n = int(input())
	angle = math.radians((n - 2) * 180 / n)
	cr = (1 - math.cos(angle)) / 2
	ans = 1 / (1 - cr)
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	a = (n - 2) * 180 / n
	angle = (180 - a) / 2
	side = math.cos(math.pi * angle / 180)
	r = side * side
	ans = 1 / (1 - r)
	print('%.8f' % ans)


import math
for a0 in range(int(input())):
	n = int(input())
	tmp = math.cos(math.radians(180 / n))
	tmp *= tmp
	print(1 / (1 - tmp))


import math
for _ in range(int(input())):
	n = int(input())
	x = math.cos(math.radians(360.0 / (2 * n)))
	ans = 1 / (1 - x ** 2)
	print(ans)


import math

def solve():
	n = int(input())
	angle = (n - 2) * 180 / n
	c = 0.5 * 0.5 + 0.5 * 0.5 - 2 * 0.5 * 0.5 * math.cos(angle * math.pi / 180)
	return 1 / (1 - c)
t = int(input())
for i in range(t):
	print(solve())


import math as m
t = int(input())
for test in range(t):
	n = int(input())
	z = m.pi * (n - 2) / n / 2
	x = m.sin(z) ** 2
	print(1 / (1 - x))


try:
	import math
	pi = math.pi
	for _ in range(int(input())):
		n = int(input())
		x = math.cos((n - 2) * pi / (2 * n))
		x = x ** 2
		print(1 / x)
except:
	pass


import math
t = int(input())
for _ in range(t):
	n = int(input())
	if n < 3:
		print(float(1))
		continue
	a = 1
	R = a / (2.0 * math.sin(math.radians(180.0 / n)))
	a_m = a ** 2 / (2 * R)
	R_m = a / 2
	s_v = (2 * R + a) / 2
	s_m = (2 * R_m + a_m) / 2
	p_v = math.sqrt(s_v * (s_v - a) * (s_v - R) * (s_v - R))
	p_m = math.sqrt(s_m * (s_m - a_m) * (s_m - R_m) * (s_m - R_m))
	q = p_m / p_v
	res = 1.0 / (1.0 - (1.0 - q))
	print(res)


import math

def solve(n):
	angle = (n - 2) * 180 / n
	angleInRadians = math.radians(angle)
	areaRatio = math.sin(angleInRadians / 2) ** 2
	return 1 / (1 - areaRatio)
t = int(input())
for tc in range(t):
	n = int(input())
	result = solve(n)
	print(result)


import sys, math, itertools, random, bisect
from collections import defaultdict
INF = 10 ** 18

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

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

def input():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	pi = math.pi
	int_angle = (n - 2) * pi / n
	angle = (pi - int_angle) / 2
	x = math.cos(angle)
	x *= x
	ans = 1 / (1 - x)
	print(ans)


import math
import sys
input = sys.stdin.readline

def fside(A):
	val = 2 - 2 * math.cos(A)
	return val
T = int(input())
for _ in range(T):
	n = int(input())
	A = math.pi - 2 * math.pi / n
	val = fside(A)
	ans = 4 / (4 - val)
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	y = 180 * (n - 2) / n
	z = 1 / 2
	new_side = 0.5 * (1 - math.cos(y * math.pi / 180))
	print(1 / (1 - new_side))


from pprint import pprint
import sys
input = sys.stdin.readline
import math

def do():
	n = int(input())
	if n == 1 or n == 2:
		raise
		assert False
	r = math.cos(math.pi / n) ** 2
	print(1 / (1 - r))
q = int(input())
for _ in range(q):
	do()


import math
t = int(input())
for f in range(t):
	n = int(input())
	print(1 / 2 * math.sin(math.pi / n * (n - 2)) / math.cos(math.pi / n * (n - 2) / 2) ** 4 / math.tan(math.pi / n * (n - 2) / 2))


import sys
import math
input = iter(sys.stdin.read().splitlines()).__next__
TC = int(input())
for tc in range(TC):
	N = int(input())
	ratio = math.cos(math.pi / N)
	res = 1 / (1 - ratio * ratio)
	print('%.010f' % res)


import math
for _ in range(int(input())):
	n = int(input())
	s = 1
	theta = 360 / n
	theta = theta * math.pi / 180
	apo = 0.5 / math.tan(theta / 2)
	A = n * s * apo / 2
	a = n * (1 / 2) * (1 / 2) * (1 / 2) * math.sin(theta)
	print(A / a)


import sys
import math
input = sys.stdin.readline
t = int(input())
for you in range(t):
	n = int(input())
	ext = 2 * math.pi / n
	inter = math.pi - ext
	inter = inter / 2
	f = math.sin(inter)
	f = f * f
	print(1 / (1 - f))