2009-01-15, 10:38 AM
Devil's Sunrise Wrote:Yeah, that works. When initiating the prime-list, you can loop like this (pseudo):
Code:loop for x = 5 then x + 6
if (isPrime(x))
add x in sieve
if (isPrime(x+2))
add x+2 in sieve
Add in 3 and remove 5, and you'll be fine. This will, most likely, increase the prime-checking part quite a lot.
I doubt it'll make much of a difference at all.
isPrime checks for multiples of 2 and 3 first (or should) and most of the time running it is spent on numbers that are actually prime.
Generating and adding the primes up to 2000000: 2.8 seconds
Incrementing the counter by 2 instead of 1 (checking 1/2 as many numbers): 2.6 seconds

