sir, I have use prime sieve method for this question Prateek loves candy with optimization but it is showing time limit in the test case. can u plzz tell why??
solution:https://ide.codingblocks.com/s/97553
Prateek loves candy challenges
Hi Khushi ,
You are running a loop till n for each testcase which increases the time complexity. No of testcases is given to be 10^4 while n can be as large as 10^6 .
Due to the n loop for every testcase , your complexity becomes O( t * n ) , which in this becomes O(10^10) . This will easily give a TLE.
Since you are already doing the precomputation for the primes in the sieve part, why to run the loop again to find the nth prime when you can also do that there and then only . Use a vector or an array to store the primes as you calculate them and then finally just output them.
Here’s your updated code - https://ide.codingblocks.com/s/97583
ok thanks sir it worked