 Find n-th Fortunate Number
Submissions: 1535   Accuracy: 33.82%   Difficulty: Easy   Marks: 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<=100
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.​

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

Contributor: Vanshika
Author: Vanshika_pec

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.