Find the closest prime number to a given number
Submissions: 3406   Accuracy:

16.8%

  Difficulty: Easy   Marks: 2

Given a number N, you have to find nearest prime number. If there are more then one, print the smaller one.

Input:
First line of input contains T denoting number of test cases. Only line of each test case contains one integers N, as described above.

Output:
For each test case output a single line containing one integer, the answer to the above problem.

Constraints:
1<= T <= 100000
2<= N <= 106

Example:
Input:

2
6
14
Output:
5
13

Explanation:
Test case 1
- for 6, both 5 and 7 are at same distance, but we need to print the smaller one, so output is 5
Test case 2-for 14, nearest prime number is 13

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Tanuj Yadav
Author: tanujyadav97


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.