Slightly optimized sieve of Eratosthenes implementation.