As The 5,000,000th prime is 86,028,121 which is nearly 1e9 so if i use sieve and precompute all the primes then it will go above 1 sec , so how to compute this 
How this will work in 1 sec
@aryan_007 The value of n is not the nth prime.
It is the value up to which you have to find the primes.
As the value of n is 5*1e6.
You can compute seive in log(log(n)). Which would take around 1e7 computations.
And it wouldn’t cause tle. Just use 0(1) time for query. And you’ll get an AC.
IF your issue has been resolved please mark this doubt as resolved.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.