Algorithm uses a prime sieve rather than call isPrime() for every number.