Help Rachit

4.8

5 votes
Problem

Rachit, one of the best programmers of Geekland university is busy in his research on prime numbers these days. Once, while roaming in the campus he saw numbers written in a spiral and he observed that many prime numbers occur on both the diagonals as shown in figure below (Yes,he is a brilliant observer).

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 :

1t105

sz is any odd value between 3 and 104

Sample Input
1
7
Sample Output
61.538462
Time Limit: 2
Memory Limit: 256
Source Limit:
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.

Contributers:
Editor Image

?