in reply to Primes. Again.
But what if there aren't enough primes in your array to check all the way up to max? You need to calculate those primes so you can check them. For all numbers from the current max stored prime + 1 to the square root of the potential prime, you check each number to see if it's a prime - using the same function! You add these primes to the stored primes array, and also check each one to see if it divides cleanly into your number. If it does divide cleanly, no further calculations are necessary, and the function returns 0.
Bottom line, only necessary calculations are made (as far as I can tell), minus a few minor tweaks such as skipping even numbers.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Primes. Again.
by johngg (Canon) on Apr 27, 2006 at 19:01 UTC |