Prateek Loves Candy( TLE )

problem link : https://hack.codingblocks.com/contests/c/787/52
solution link: https://ide.codingblocks.com/s/81350

Even after using prime sieve it is giving tle. Can anybody suggest, what
I am doing wrong.

Finally got the problem. The problem was not with sieve of eratosthenes, the problem was with
the constraints on testcases, because for every test case I was finding the prime numbers upto that number and at last returning the last prime number found, this wasl causing the TLE for big test cases.

So, to overcome this problem, I stored test cases in an array

Here is the solution which finally got accepted

1 Like

good explanation
why you have declared arrays in global space? does it affect time complexity ?