PrimeCalc

About this project
Sample Lehmer prime number generator.
Wiki / Home

Welcome

For background information on why this sample program exists, see:
http://www.orthogonal.com.au/lehmer/index.htm

A command line application that generates the 133 pages of Lehmer's influential book List of Prime Numbers from 1 to 10,006,721. Washington, DC: Carnegie Institution, 1914

The code deliberately uses the inefficient classical school book technique of testing for primality by trial division up to the square root.

There is a simple performance boost in the code: instead of stupidly using sequential trial divisors like [2,3,4,5,6,7,...], it starts with [2,3] then uses numbers of the form 6±1 [5,7,11,13,17,19,23,25,...]. This means that only one-third of integers are candidate divisors. A wheel could be used to further reduce the candidate divisors, but it's overkill for this simple demo program.

Note that Lehmer insisted on listing 1 as the first prime. The mathematical community never adopted that convention and they consider 2 to be the first prime, and 1 to be the unit. The integer 2 is a bit of a rogue case because it's the only even prime, and it often forces mathematical articles to start with the phrase "let p be an odd prime". There is a related mathematical joke:

Q. What is the oddest prime?
A. 2 ... because it's the only even one.

Lehmer Page 1 Extract

Orthogonal Programming Link