| PRIMECOUNT(1) | PRIMECOUNT(1) |
NAME¶
primecount - count prime numbers
SYNOPSIS¶
primecount x [options]
DESCRIPTION¶
Count the number of primes less than or equal to x (<= 10^31) using fast implementations of the combinatorial prime counting function algorithms. By default primecount counts primes using Xavier Gourdon’s algorithm which has a runtime complexity of O(x^(2/3) / log^2 x) operations and uses O(x^(2/3) * log^3 x) memory. primecount is multi-threaded, it uses all available CPU cores by default.
OPTIONS¶
-d, --deleglise-rivat
--double-check
-g, --gourdon
-l, --legendre
--lehmer
--lmo
-m, --meissel
--Li
--Li-inverse
-n, --nth-prime
-p, --primesieve
--phi X A
-R, --RiemannR
--RiemannR-inverse
-s, --status[=NUM]
--test
--time
-t, --threads=NUM
-v, --version
-h, --help
ADVANCED OPTIONS FOR THE DELEGLISE-RIVAT ALGORITHM¶
--P2
--S1
--S2-trivial
--S2-easy
--S2-hard
Tuning factor¶
The alpha tuning factor mainly balances the computation of the S2_easy and S2_hard formulas. By increasing alpha, the runtime of the S2_hard formula usually decreases, while the runtime of the S2_easy formula increases. By default, primecount automatically selects an alpha tuning factor that is likely to provide the best performance for the user’s input.
The alpha tuning factor is also very useful for double checking pi(x) computations. You compute pi(x) twice but for the second computation you use a slightly different alpha factor. If the results of both pi(x) computations match then pi(x) has been verified successfully.
-a, --alpha=NUM
ADVANCED OPTIONS FOR XAVIER GOURDON’S ALGORITHM¶
--AC
--B
--D
--Phi0
--Sigma
Tuning factors¶
The alpha_y and alpha_z tuning factors mainly balance the computation of the A, B, C and D formulas. When alpha_y is decreased and alpha_z is increased, the runtime of the B formula increases, while the runtime of the A, C and D formulas decrease. By default, primecount automatically selects alpha_y and alpha_z tuning factors that are likely to provide the best performance for the user’s input.
Both the alpha_y and alpha_z tuning factors are also very useful for double checking pi(x) computations. You compute pi(x) twice but for the second computation you use slightly different alpha_y and/or alpha_z tuning factors. If the results of both pi(x) computations match then pi(x) has been verified successfully.
--alpha-y=NUM
--alpha-z=NUM
DOUBLE CHECKING PI(X) COMPUTATIONS¶
For large pi(x) computations that run over several weeks or months, it is important to verify such computations to protect against miscalculations due to hardware errors and/or bugs in primecount.
To verify a pi(x) computation, you compute pi(x) twice. But for the second run you use the --double-check option. The --double-check option enables the use of alternative alpha tuning factor(s), ensuring that all internal bounds in the second computation differ slightly from the first run. This redundancy helps guard against potential bugs in primecount: if an error exists, it is highly unlikely that both pi(x) computations would produce the same (incorrect) result.
primecount 1e20 --status
primecount 1e20 --status --double-check
EXAMPLES¶
primecount 1000
primecount 1e17 --status
primecount 1e15 --threads 1 --time
HOMEPAGE¶
AUTHOR¶
Kim Walisch <kim.walisch@gmail.com>
| 11/16/2025 |