TLE for all test cases

I’ve used a Bitset for sieve in the solution. Still its giving TLE for all test cases.

Could you please tell what I’m doing wrong here?

Check now

You can refer this https://ide.codingblocks.com/s/285203 implementation

still getting the same TLE issue.

Could you please tell me why are we incrementing j += (2 * i)

Prime numbers are never even.
You know that i is odd.
j = i * i which is also odd.
j+=i will also give even values (as odd + odd =even). This is not required.
So j+=2 * i will also do

thanks a lot. got it… in addition to this, I had to increase the size of the sieve array as well.

earlier my sieve array size was 10^8, but when I increased this to 10^9, all test cases were passing. But it should’ve worked with 10^8 as well, right?

It is given
Constraints

1<=n<=500000

So it may be that 500000th prime number of order > 10^8

okay, thanks for the help. :slight_smile: