Update ... Monday morning ... Final runs are underway, results by tonight .... in the meantime, here's some more reading material! =Fred ********************************************************************** * You can thank Rich Coco (Seive, Fermat, Euler), Bob Hall (Miller-Rabin), * Jim Roche, Allan Wilks, and the POTM-master for this file. * ... with any sort of luck, it's actually both accurate and useful! * ==================================================================== * MATHEMATICS BACKGROUND * ==================================================================== * * There are four methods that may be of interest in determining * prime numbers described in this mail: * * The Seive of Eratosthenes generates a list of prime numbers; * The Miller-Rabin test produces a strong likelihood of primality * by examining the modulus of an exponetiation operation; * Fermat's Method is a method for testing primality by investigating * whether a number can be decomposed into the difference of 2 squares; * Euler's Method is another method for testing primality by investigating * whether a number can be decomposed into the sum of 2 squares. * * Plus some useful tricks you may not have known about!!! * * Consider the nine digit number X = d8d7d6d5d4d3d2d1d0 .... * * well, we all know that if N = d8+d7+d6+d5+d4+d3+d2+d1+d0 is divisible * by 9, then X is divisible by 9. More importantly for this problem, * if N is divisible by 3, then X is divisible by 3. * * and, of course, by looking at d0 we can figure out if X is divisible * by 2 or by 5. * * BUT ... here's three more you may not have known about * courtesy of Allan Wilks and me!!! * * if N = (d0-d3+d6) + 2*(d2-d5+d8) + 3*(d1-d4+d7) is divisible by 7 * then X is divisible by 7. Did I hear someone say howcum???? * Well it's true, and I'll send you the proof ... but I found it * to be fun to try and prove it myself. (Gee, guess I need a life!) * * if N = d0-d1+d2-d3+d4-d5+d6-d7+d8 is divisible by 11, then X * is divisible by 11 ... try proving this one before you tackle the 7s! * * if N = (d0-d3+d6) - 3*(d1-d4+d7) - 4*(d2-d5+d8) is divisible by 13, * would you believe that X is divisible by 13 ??? * * Now .... on to the heavy stuff !!!! * * ==================================================================== * 1. Eratosthene's Seive * * Eratosthene's Seive basically involves stepping through * a contiguous sequence of integers (starting from 2) * removing all multiples of the current integer. * The ones that remain are prime. * To determine all the primes that might divide a given * number N, it suffices to seive the sequence bounded by * [sqrt(N)] ([x] = integr part of x). * * For this POTM, N < 10^9 (1 billion) * There are roughly 50,847,478 primes embedded in the first * one billion natural numbers! * However, we need only look at primes less than x^(1/2) * to determine if x is prime. For x = 1,000,000,000, x^(1/2) = 31622.78 * **************************************************************************** * The following is a program fragment (from the POTM-master entry) that * implements the sieve with no multiplication ... courtesy of Knuth! **************************************************************************** /* Prepare for the job of prime-finding by computing all the possible factors of numbers less than 10^9 ... it turns out that there are 3401 of them (including 2) ... */ /* This is the Sieve of Eratosthenes as described in Knuth, Vol 2, section 4.5.4 problem 8 applied to the proiblem of finding all odd primes less than the square root of 10^9 without doing any multiplication ... the list is stored in prime_list[i] */ JMAX=15812; /* 2*JMAX > sqrt(1,000,000,000) */ /* there should be 3401 of them (with 2) */ prime_list[1]=2; i=1; for(k=1; k