Prime Sieve for 500000th limit

Hi while solving the prime sieve problem, i noticed the constraints say N<=500000, while i have been able to pass the current testcases, my code isn’t able to actually meet this constraint and find the 500000th prime number or even the 499999th prime number.
i have tried increasing the max_size but the code crashes anyways… can you please look into it and let me know what i can do to meet this constraint with my code??
here’s a link: https://ide.codingblocks.com/s/306209

Thanks!

@ilovetocode your code seems fine but i guess there may be some ide limit or else which is causing error and i too am unable to find it,here is a same code like your but changed a little bit try to take help from here https://ide.codingblocks.com/s/306240.

Hi, thanks for the quick response!
The code you linked actually doesn’t crash, so if it was an ide limit, this shouldn’t have worked…
The concept looks similar to mine, so either i made some blunder somewhere or you have used some space and time optimization techniques to have made this work for you.
Can you please tell me what this technique/correction could be?? i have been through both codes a number of times, what can i change in my attempt to make it work??

Thanks again!

some little difference between yours and mine is like i have taken arr of type bool since we need only 0 or 1,and inside nested for loop maybe storing x*x in y may cause error if x is of bigger size.this are some little things which are mainly ignored by everyone but in tight constraint we may get errors.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.