Help Rachit
Practice
4.8 (5 votes)
Algorithms
Approved
Dynamic programming
Math
Medium
Number theory
Open
Primality test
Problem
39% Success 2532 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

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 :

\( 1 \le t \le 10^5\)

\(sz\) is any odd value between 3 and \(10^4\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
14 votes
Tags:
C++Primality TestsMathNumber Theory
Points:20
2 votes
Tags:
Easy
Points:30
3 votes
Tags:
MathMediumNumber TheoryPrimality test