primesum is a command-line program that computes the sum of the primes below an integer x ≤ 1031 as quickly as possible using a modified version of the combinatorial prime counting function algorithm [1]. primesum has already been used to compute many new prime sum world records!
primesum is a modified version of the author's primecount program.
You need to have installed a C++ compiler which supports 128-bit integers and OpenMP (e.g. GNU GCC or LLVM/Clang) and CMake ≥ 3.9.
| Arch Linux: | sudo pacman -S gcc cmake |
| Debian/Ubuntu: | sudo apt install g++ cmake |
| Fedora: | sudo dnf install gcc-c++ cmake |
| macOS: | brew install cmake libomp |
| openSUSE: | sudo zypper install gcc-c++ cmake |
# Linux
cmake .
cmake --build . --parallel
# macOS
CXXFLAGS="-I$(brew --prefix libomp)/include" LDFLAGS="-L$(brew --prefix libomp)/lib" cmake .
cmake --build . --parallelOpen a terminal and run primesum using:
# Sum the primes below 10^14
./primesum 1e14
# Print progress and status information during computation
./primesum 1e18 --status
# Use 4 threads and print time elapsed
./primesum 1e14 --threads=4 --time
# Run tests
./primesum --testUsage: primesum x [OPTION]...
Sum the primes below x <= 10^31 using fast implementations of the
combinatorial prime summing function.
Options:
-d, --deleglise_rivat Sum primes using Deleglise-Rivat algorithm
-l, --lmo Sum primes using Lagarias-Miller-Odlyzko
-s[N], --status[=N] Show computation progress 1%, 2%, 3%, ...
[N] digits after decimal point e.g. N=1, 99.9%
--test Run various correctness tests and exit
--time Print the time elapsed in seconds
-t<N>, --threads=<N> Set the number of threads, 1 <= N <= CPU cores
-v, --version Print version and license information
-h, --help Print this help menu
Advanced Deleglise-Rivat options:
-a<N>, --alpha=<N> Tuning factor, 1 <= alpha <= x^(1/6)
--P2 Only compute the 2nd partial sieve function
--S1 Only compute the ordinary leaves
--S2_trivial Only compute the trivial special leaves
--S2_easy Only compute the easy special leaves
--S2_hard Only compute the hard special leaves
| x | Sum of the primes below x | Time elapsed |
| 1010 | 2,220,822,432,581,729,238 | 0.00s |
| 1011 | 201,467,077,743,744,681,014 | 0.01s |
| 1012 | 18,435,588,552,550,705,911,377 | 0.02s |
| 1013 | 1,699,246,443,377,779,418,889,494 | 0.04s |
| 1014 | 157,589,260,710,736,940,541,561,021 | 0.11s |
| 1015 | 14,692,398,516,908,006,398,225,702,366 | 0.35s |
| 1016 | 1,376,110,854,313,351,899,159,632,866,552 | 1.04s |
| 1017 | 129,408,626,276,669,278,966,252,031,311,350 | 3.67s |
| 1018 | 12,212,914,292,949,226,570,880,576,733,896,687 | 16.75s |
| 1019 | 1,156,251,260,549,368,082,781,614,413,945,980,126 | 91.60s |
| 1020 | 109,778,913,483,063,648,128,485,839,045,703,833,541 | 486.25s |
The benchmarks above were run on an Intel Core Ultra 5 245K CPU from 2024 with 14 CPU cores and primesum was compiled using GCC 16.2.
A046731 world records
| x | Sum of the primes below x | Date | Computed by |
| 1021 | 10449550362130704786220283253063405651965 | June 6, 2016 | Kim Walisch |
| 1022 | 996973504763259668279213971353794878368213 | June 6, 2016 | Kim Walisch |
| 1023 | 95320530117168404458544684912403185555509650 | June 11, 2016 | Kim Walisch |
| 1024 | 9131187511156941634384410084928380134453142199 | June 17, 2016 | David Baugh |
| 1025 | 876268031750623105684911815303505535704119354853 | Oct. 16, 2016 | David Baugh |
| 1026 | 84227651431208862537105979544170116745778105437780 | May. 25, 2022 | Kim Walisch |
Note that the sum of the primes below 10^21 was already correctly computed by Marc Deléglise in 2009 but when he verified the result using his program he found a different result (off by 1) so he withdrew his result in 2011.
A099824 world records
| n | Sum of the first n primes | Date | Computed by |
| 1018 | 21849887810843912935127758942358047227 | June 5, 2016 | Kim Walisch |
| 1019 | 2302808849326957165657230565155878163277 | June 5, 2016 | Kim Walisch |
| 1020 | 242048824942159504049568772767666927073373 | June 5, 2016 | Kim Walisch |
| 1021 | 25380411223557757489768734384174904646137001 | June 11, 2016 | Kim Walisch |
| 1022 | 2655479563137417712148525630666125075397977159 | June 22, 2016 | David Baugh |
| 1023 | 277281399946560013844427926899019949823102890613 | Sep. 26, 2016 | David Baugh |
| 1024 | 28900534863094599803598612528087047372125211931087 | June 17, 2022 | Kim Walisch |
A130739 world records
| n | Sum of the primes < 2^n | Date | Computed by |
| 271 | 57230460176857192458791870659870195302414 | Dec. 26, 2017 | Kim Walisch |
| 272 | 225709510085333603256262210540764048485810 | Dec. 26, 2017 | Kim Walisch |
| 273 | 890344379866902468590503993853978913148982 | Dec. 26, 2017 | Kim Walisch |
| 274 | 3512767258692956754932236839569828523905141 | Dec. 26, 2017 | Kim Walisch |
| 275 | 13861865005427848960138734445963535022604898 | Dec. 26, 2017 | Kim Walisch |
| 276 | 54710756810055087402063527107893581408200826 | Dec. 26, 2017 | Kim Walisch |
| 277 | 215973500680654121229780243886194476543303643 | Dec. 26, 2017 | Kim Walisch |
| 278 | 852713035956963663153441533770552801919275705 | Dec. 26, 2017 | Kim Walisch |
| 279 | 3367271267053300856599603567833163229921782198 | Dec. 26, 2017 | Kim Walisch |
| 280 | 13299160452380363326976224185417674340116996121 | Dec. 26, 2017 | Kim Walisch |
- M. Deléglise and Jean-Louis Nicolas, Maximal product of primes whose sum is bounded, 3 Jul 2012, https://arxiv.org/abs/1207.0603.