PRIMECOUNT(1)
β¨ NAME β¨
primecount β count prime numbers. Bestie, this is the primecount(1) manual page, and it's literally here to count primes for you. π
πΈ SYNOPSIS πΈ
primecount x [options]
π¦ DESCRIPTION π¦
Okay so primecount counts 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, and it uses all available CPU cores by default. Iconic behavior, honestly. π₯
π OPTIONS π
-d,--deleglise-rivatβ Count primes using the Deleglise-Rivat algorithm.--double-checkβ Recomputepi(x)with alternative alpha tuning factor(s) to verify the first result. This redundancy helps guard against potential bugs inprimecount: if an error exists, it is highly unlikely that bothpi(x)computations would produce the same (incorrect) result.-g,--gourdonβ Count primes using Xavier Gourdonβs algorithm. This is the default algorithm.-l,--legendreβ Count primes using Legendreβs formula.--lehmerβ Count primes using Lehmerβs formula.--lmoβ Count primes using the Lagarias-Miller-Odlyzko algorithm.-m,--meisselβ Count primes using Meisselβs formula.--Liβ Approximatepi(x)using the Eulerian logarithmic integral:Li(x), withLi(x) = li(x) - li(2).--Li-inverseβ Approximate the nth prime using the inverse Eulerian logarithmic integral:Li^-1(x).-n,--nth-primeβ Calculate the nth prime.-p,--primesieveβ Count primes using the sieve of Eratosthenes.--phi X Aβphi(x, a)counts the numbers<= xthat are not divisible by any of the firstaprimes.-R,--RiemannRβ Approximatepi(x)using the Riemann R function:R(x).--RiemannR-inverseβ Approximate the nth prime using the inverse Riemann R function:R^-1(x).--RiemannR-psiβ Approximatepi(x)using a refined Riemann R approximation based onR(psi(x)). Compared to--RiemannR, this option first approximates Chebyshevβspsi(x)using Riemannβs explicit formula with the first512zeta zero gammas and then evaluatesR(psi(x)). In practice this usually estimatespi(x)more accurately than plainR(x).--RiemannR-psi-inverseβ Approximate the nth prime using the inverse of the refinedR(psi(x))approximation. Compared to--RiemannR-inverse, this option inverts the psi-corrected approximation instead of plainR(x). In practice this usually estimates the nth prime more accurately thanR^-1(x).-s,--status[=NUM]β Show the computation progress e.g.1%,2%,3%, ... ShowNUMdigits after the decimal point:--status=1prints99.9%.--testβ Run various correctness tests and exit.--timeβ Print the time elapsed in seconds.-t,--threads=NUMβ Set the number of threads,1 <= NUM <= CPU cores. By defaultprimecountuses all available CPU cores.-v,--versionβ Print version and license information.-h,--helpβ Print this help menu.
π ADVANCED OPTIONS FOR THE DELEGLISE-RIVAT ALGORITHM π
--P2β Compute the 2nd partial sieve function.--S1β Compute the ordinary leaves.--S2-trivialβ Compute the trivial special leaves.--S2-easyβ Compute the easy special leaves.--S2-hardβ Compute the hard special leaves.
π 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. So thoughtful of it. π«Ά
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β Set the alpha tuning factor:y = x^(1/3) * alpha,1 <= alpha <= x^(1/6).
π ADVANCED OPTIONS FOR XAVIER GOURDONβS ALGORITHM π
--ACβ Compute theA + Cformulas.--Bβ Compute theBformula.--Dβ Compute theDformula.--Phi0β Compute thePhi0formula.--Sigmaβ Compute the 7 Sigma formulas.
π§ 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. It's giving optimized. β¨
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β Set thealpha_ytuning factor:y = x^(1/3) * alpha_y,1 <= alpha_y <= x^(1/6).--alpha-z=NUMβ Set thealpha_ztuning factor:z = y * alpha_z,1 <= alpha_z <= x^(1/6).
π 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. No cap, this is the safety-girl era. π
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
First pi(x) computation using default alpha tuning factor(s).
primecount 1e20 --status --double-check
Second pi(x) computation using alternative alpha tuning factor(s).
π EXAMPLES π
primecount 1000
Count the primes <= 1000.
primecount 1e17 --status
Count the primes <= 10^17 and print status information.
primecount 1e15 --threads 1 --time
Count the primes <= 10^15 using a single thread and print the time elapsed.
π¦ HOMEPAGE π¦
https://github.com/kimwalisch/primecount
π AUTHOR π
Kim Walisch <kim.walisch@gmail.com>
π Cute little sign-off: that's the wholePRIMECOUNT(1)manual page, source/versionPRIMECOUNT(1), dated04/16/2026. Now go verify yourpi(x)twice, hydrate, and slay. π«Άβ¨
π¦ where this page comes from
- arch rolling: primecount 8.8-1 Β· BSD-2-Clause
- nixpkgs unstable: primecount 8.5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms