It works fine locally but gives runtime error on submitting. The link to code - https://ide.codingblocks.com/s/160155
My code gives runtime error but i cant figure out why
Use segmented sieve correctly.
Please refer this code for better explanation.
Can you point out error in my code, as I have implemented exactly what was taught to us in course
First of all return 0 in main, this causes a runtime error. Second, you are not implementing segmented sieve correctly, you have to go to the multiples of prime and then marked then true. But you are also traversing composite numbers. That’s why you get TLE in two test cases.
Please refer to the above code, it will help you understand better.
Thanks a lot for pointing return 0;
Secondly I agree that I am doing unwanted work. So I corrected my code and still I failed to pass test case 0. So I started to study your code!
Although I get the intuition of line 82 :
int l = ceil( m / double(primes[i]) ) * primes[i];
I think we start from lowest multiple of each prime in given range and continue our search over space, this is what it is for, right?