Square in a Circle
A square is kept inside a circle. It keeps expanding until all four of
its vertices touch the circumference of the circle. Another smaller circle is
kept inside the square now and it keeps expanding until its circumference
touches all four sides of the square. The outer and the inner circle form a
ring. Find the area of this ring.
Input
Input consists of multiple test cases.
Each test case contains one integer denoting the
side-length of the square between the two circles.
Output
Print the area of the ring.
Sample Input 0
3
3
4
5
Sample Output 0
7.068583
12.566371
19.634954
Code:
import math
t=int(input())
while(t!=0):
t-=1
q=int(input())
a_o=q/math.sqrt(2)
a_i=q/2
print("%.6f"%(math.acos(-1)*(a_o*a_o - a_i*a_i)))
Comments
Post a Comment