Prime numbers storage

How we store the prime numbers.

The storage of the generated and validated prime numbers is optimized by using an efficient compression algorithm described in the following article: High Performance Storage of Prime Numbers. Zenodo. https://doi.org/10.5281/zenodo.23733895.

Segment and range

A production segment spans 446,185,740 integers, represented as two blocks of 223,092,870 integers each. Its canonical raw bitmap is exactly 9,123,840 bytes.

The first segment is physically aligned at zero, but its published logical range starts at 24 because the primes 2, 3, 5, 7, 11, 13, 17, 19 and 23 are implicit and are not stored in the bitmap.

23# coprime reduction

Each 223,092,870-integer block represents only the 36,495,360 residues coprime to 23# (the product of the primes through 23). Two such blocks make one production segment. The format 4 raw bitmap is gzip-compressed directly, without a zero-mask encoding layer.

Gzip/raw and gzip bytes per prime are shown by range N on a logarithmic scale up to 1012.

The first point will appear after a segment is validated.

Convert a segment to text

The standalone Python 3 script reads version 4 .bin.gz files containing a directly gzipped raw bitmap, as well as uncompressed raw bitmaps. It writes one represented prime per line and requires no third-party package.

Download the Python converter

python3 primefiles-to-text.py primefiles-000001-446185740-892371480-coprime23-v4.bin.gz

# If the file was renamed, give its physical bitmap start:
python3 primefiles-to-text.py segment.bin.gz primes.txt --start 446185740

# Optionally include the nine implicit primes when converting segment 0:
python3 primefiles-to-text.py primefiles-000000-24-446185740-coprime23-v4.bin.gz \
  --include-implicit-small-primes

Keep the original public filename when possible: the script can then infer the range automatically, including the special physical alignment of segment 0.