spoj problem 2

Last edited on
As already mentioned in the comments on the SPoJ problem you linked to, brute force is not adequate to solve the problem. Change your algorithm.
Generate all the prime numbers first before reading the inputs

Hint: Use prime sieve
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
Topic archived. No new replies allowed.