Prateek loves candy time limit exceeded

https://ide.codingblocks.com/s/47938

sir when i ran this code for test cases, it showed time limit exceeded… how to fix this error?

Hey Yukti, One important this is when you declare a function it should be outside main(), there is no point of declaring void nprime(int); inside the main(). Second is you are getting TLE because for each case you are finding the nth prime no. using a loop, so you are supposed to use sieve of eratosthenes here to remove the TLE. If you haven’t watched yet there is a video given in the online course of sieve of eratosthenes.

I was also getting the same error and I tried using sieve of eratosthenes. Now I am getting Run-Time Error. The code is working fine in the IDE but showing an error only when I submit Code in the problem section.
https://ide.codingblocks.com/s/51323

Hey Anushka, your code isn’t working check for this
input:
2
50000
50001

your code’s output:
1
1

but expected output is:
611953
611957

also, your are make array of k*3 it will not work everytime and by saying use sieve of eratosthenes means make the sieve once at the starting and then take output from this for each case, don’t make the sieve again for each test case.

But how to decide the size of the array?
I corrected those errors and now I am getting Time Limit in this code
https://ide.codingblocks.com/s/51323