Time limit exceeds
For each test case you are iterating the whole sieve to find the nth prime number which is inefficient, so what you should do is store first 10^6 prime numbers in an array or vector and when you get an test case just return nth index of that array this way you can solve for each test case in O(1) rather than O(n*log(log(n)).
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.
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.