prime
0.4
Prime Number Generation
|
This project is for calculating and storing prime numbers. It uses the Sieve of Eratosthenes to mark bits in a block of memory. As there are an infinite number of prime numbers, this class can apply the sieve to an ever increasing list of blocks. I'm maintaining a wiki with more information.
For version 0.4, it is limited to size_t (64 bits). The plan is to extend this out to "__int128" (128 bits) or use one of the "infinite" bit classes for integers. You will likely run out of disk space before using up size_t space.
Storage of the prime numbers, at least the initial numbers, is inefficient as a list. Storage of a bit for each number (true for prime) is initially more efficient. This list of bits can be cut in 1/2 by only storing odd numbers. It can be further cut by 1/3 by eliminating numbers divisible by 3, 1/5 by eliminating numbers divisible by 5 and so on. Since future cuts beyond 5 give diminishing returns, version 0.3 stops here. I invite anyone with a more efficient method to let me know of your solution so I can further compress the data.
P.S. The most efficient way to store these numbers is to just store the algorithm. However, we want to be able to look up the numbers in roughly constant time.
Some useful links:
Some next steps are:
While C++ is efficient, Python is more fun for trying out clever ideas. Some next "fun" steps are:
Motivation: This is just a fun project. I got a scholarship to the University of Florida for some work I did with prime numbers in high school. It took me days to calculate a set of prime numbers that today can be calculated in a few seconds.
Changes since Last Version:
For version 0.4: Mainly updated for OpenMP inlcuding a number of new test cases for validation. The numbers have been validated up to 11,020,102,204,020 which contains 380,088,301,203 primes. Thanks to Andrew Booker for this : https://primes.utm.edu/nthprime/index.php#piofx
For verison 0.3 the following changes were made:
For version 0.2, the following changes were made: