Mr. NU Goes Missing

0

0 votes
Problem

A new problem arises at the end of the Success party, Mr. NU, the official mascot of NU-Tech'15 which has been a topic of interest throughout this Tech-fest goes missing in a Spiral Maze of Numbers and the whole NU-Tech team has panicked due to it.

enter image description here

The Robotics team designed a robot on Mr. NU's design which was supposed to walk a Spiral Matrix as shown below in the ascending order of the numbers in it starting from 1 and to take halts whenever it came on one of its diagonals. But, there has been some problem and now, Mr. NU is stopping only on those diagonal elements which have their GCDs equal to 1 with all the numbers less than them. In order to locate Mr. NU in the Spiral Matrix again, the Robotics team needs to know the percentage of elements on the diagonals on which Mr. NU would have stopped. Help the Robotics team relocate Mr. NU.

37 36 35 34 33 32 31

38 17 16 15 14 13 30

39 18 5 4 3 12 29

40 19 6 1 2 11 28

41 20 7 8 9 10 27

42 21 22 23 24 25 26

43 44 45 46 47 48 49

He is very curious to know what percentage of prime numbers is there on both the diagonals to that to all the numbers on the diagonal. your task is to write a program to help rachit.

NOTE: Value of n is always going to be odd.

Input:

First line of input contains an integer t, which is the number of test cases. t lines follow, with each test containing an integer which is the size of spiral matrix (Size of above matrix is 7).

Output: For each test case output a single line which is the percentage of number of prime numbers on the diagonal to the total numbers on diagonal, correct to six decimal places.

Constraints :

1 <= t <= 10^5

size is any odd value between 3 and 10^4

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Explanation The above spiral represents the spiral of size 7. Numbers on the diagonal are: 37, 17, 5 ,1, 9, 25, 49, 31, 13, 3 ,7, 21, 43 Out of which prime numbers are: 37, 17, 5, 31, 13, 3, 7, 43

61.538462% of total numbers on diagonal are prime numbers.

Editor Image

?