

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.
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.
For each query, return the Nth prime number.
Print the output of each query in a separate line.
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
Consider a function FINDPRIME that takes number N as input parameter and do:
We can use some basic OOPs techniques to reduce complexity. We'll create a global sieve and store values of prime numbers in it and use it to get prime numbers for all queries in constant time.
Now, once the array is created, you can check and return ARRAYOFPRIMES[N]. Thus the retrieval of Nth prime number can be done in constant time.
Consider function FINDNTHPRIME that accepts an integer N as a parameter and do:
Pair Product Div by K
Pair Product Div by K
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
First Digit One
Special Digit Numbers