View Single Post
Old 02-06-2005, 06:04 PM   #7 (permalink)
Rekna
Junkie
 
Here are some optimizations you should implement.

First always increment your counter by 2 (only check if odd numbers are prime, 2 is the only even prime number).

Second save a list of the primes you find and instead of checking if a number is prime by dividing by all numbers between 2 and N only try dividing other primes into it. There is no reason to try and divide non prime numbers into it, as they will already be checked via other primes.
Rekna is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43