Im reaching timelimit although im following erathosthenes sieve just once
Hi Anchal,
This is because you are computing the nth primes from the sieve array for each testcase seperately. Instead do some precomputation. Make an array or a vector where you can store the prime numbers already . Lets call it “primes” .
Initialise the first element of primes as 2 and then push the prime numbers into this array/vector while doing the sieve computations. That is , whenever you hit the if condition at Line No. 17 , push the value i into primes.
Once you are done with sieve function , you not only have your sieve array ready but also the primes array ready having all the prime numbers in order.
Now simply output the nth value from the primes array for each testcase that you have already precomputed.
This will bring down your time complexity from O(t * n) to O(t + n) which is a vast improvement given the constraints on this question.