Find n-th Fortunate Number
Easy Accuracy: 35.2% Submissions: 1727 Points: 2

Given an integer n, find the nth Fortunate Number.
A Fortunate number is the smallest integer m > 1 such that, for a given positive integer n, pn + m is a prime number. Here pn is the product of the first n prime numbers, i.e prime factorials (or primorials) of order n.

Input:
The first line contains an integer T, number of test cases. For each test case, there is an integer n.

Output:
For each test case, the output is an integer displaying the nth Fortunate Number.

Constraints:
1 <= T <= 10
1 <= n <= 10

Example:
Input:

2
3
5
Output:
7
23

Explanation:
1.
​7 must be added to the product of first n prime numbers to make the product prime. 2 x 3 x 5 = 30, need to add 7 to make it 37, which is a prime.
2.​ 23 must be added to the product of first n prime numbers to make the product prime. 2 x 3 x 5 x 7 x 11= 2310, need to add 23 to make it 2333, which is a prime.​


 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.