Please check my code…why is it giving TLE?
Code Giving TLE
If in case you are not using Prime Sieve here, it will give TLE.
You can refer this code for help https://ide.codingblocks.com/s/243914
I am so sorry i thought my subission was shared automatically .
Check now
its running now thanks a lot…Also can you please explain what you did? and about this magical upper limit
I just changed the increment in line number 12.
Previously you were doing j=j+i
You know that j is odd and also when prime[i]=1 then i is also odd.
ODD + ODD= EVEN So j=j+i will result in an even number and even number cannot be a prime.
So i changed it to j=j+2 * i since ODD+ EVEN gives an odd number.
yes that i understood but i didn’t get how you changed and decided the limit of all the loops
I did not change the limits of the loop. I just changed line 12.
The constraints giiven in the question is
Constraints
1<=n<=500000
So accordingly yo have to decide the limits of the loop. Values of order 10^8 must contain all the answers .So in this way you can take the limits of the loop.