

You are given a number 'N'. Your task is to find Nth prime number.
A prime number is a number greater than 1 that is not a product of two smaller natural numbers. Prime numbers have only two factors – 1 and the number itself.
Any number greater than 0 is a natural number i.e. natural numbers N = {1, 2, 3, 4,....}
For example:-
If you are asked to find the 7th prime number, it’ll be 17 because the first 7 prime numbers are 2, 3, 5, 7, 11, 13, 17.
Note: 1 is not a prime number.
Follow Up:Try to solve the problem in O(N log log N) + O(N).
The first line of input contains an integer 'Q' representing the number of the queries. Then Q queries follow:
The first line of each query contains an integers ‘N’ representing the number of a prime number to be found.
Output Format :
For each query, return the Nth prime number.
Print the output of each query in a separate line.
Note:
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= Q <= 100
1 <= N <= 10^4
Time Limit: 1 sec
3
5
2
1
11
3
2
For the first query, the prime numbers are [2, 3, 5, 7, 11]
For the second query, the prime numbers are [2, 3]
For the third query, the prime number is [2]
3
46
20
13
199
71
41
Try to check for each element, if it is prime or not and find Nth number that is prime.
Consider a function FINDPRIME that takes number N as input parameter and do:
O(Q * N^2), where N represents the Nth prime number that we have to find.
Since we are dividing every ith number from numbers from 2 to i, therefore, the time complexity of the approach is O(Q * N^2).
O(1),
The space complexity of the approach is O(1) because no extra memory is required.