Time limit exceeded


I wrote an optimized code for this program but it is still showing time limit exceeded. How can I optimize it still more

Hi @tanjuljain19,
See the test case of this problem can vary largely and counting the primes is a long process . It would be fairly nice to compute a array which stores which number of prime is that number . For example let the array be prime and if we want to know the n=3 prime number means the third prime number then we simple check the index of prime[3] and the third prime number will be stored on it. So prime array will store somewhat like this prime[0]=empty or 0 prime[1]=2 prime[2]=3 prime[3]=5 prime[4]=7 prime[5]=11 prime[6]=13 … and so on… i hope you understand the concept. And make sure you compute this array and once and store before test case so that you do not have to compute it again for each test case and can just use the value to answer the testcase.