How do we optimize this code further? Since the constraint is 500k
Deepak and primes
Take array size for prime sieve as 10^7, this is enough to get first 500k primes!
Also to answer for nth prime, pre-store the primes into another container (say primes[ ]) so that you can directly print primes[n-1].
Time Complexity is (nlogn) is it is acceptable!
Now?
array size is still small!
take MAX_SIZE as 10000007
Still getting segmentation fault
@mayankA47
I don’t know what’s happening, I am getting segmentation fault in all prime problems.
I have another doubt once cleared with the previous one.
.
.
Prime visits
see this it works fine!
Sometimes creating such large arrays within main() creates seg fault, in such cases you can declare it as global.
@mayankA47 still not working
https://ide.codingblocks.com/s/248598 //deepak and prime
https://ide.codingblocks.com/s/248588 //prime visits
see your mistakes , also develop a habit of dry running code to catch possible bugs, overflow was one of them here
What is the use of int32_t main? I mean how it actually differs from int main?
I have never used before
Okay, I got this. May be because of using integer instead of long long?
Thank you 