PRIMESIEVE(1)
π PRIMESIEVE(1) β the primesieve page, bestie edition π
okay so this is the manual for primesieve, and yes it's giving "math but make it fashion" β it generates prime numbers, and it does it fast. Buckle up π
β¨ NAME β¨
primesieve β generate prime numbers, that's the whole job, and it ate π
πΈ SYNOPSIS πΈ
primesieve [START] STOP [OPTION]...
π¦ DESCRIPTION π¦
Generate the prime numbers and/or prime k-tuplets inside [START, STOP] (< 2^64) using the segmented sieve of Eratosthenes. Not me explaining ancient Greek math at a sleepover β but fr fr, it works.
primesieve includes a number of extensions to the sieve of Eratosthenes which significantly improve performance, and honestly? obsessed:
- multiples of small primes are pre-sieved
- it uses wheel factorization to skip multiples with small prime factors
- it uses the bucket sieve algorithm, which improves cache efficiency when sieving
> 2^32
primesieve is also multi-threaded β it uses all available CPU cores by default for counting primes and for finding the nth prime. main character energy, it refuses to use just one core π
The segmented sieve of Eratosthenes has a runtime complexity of O(n log log n) operations and it uses O(n^(1/2)) bits of memory. More specifically primesieve uses 8 bytes per sieving prime, hence its memory usage can be approximated by PrimePi(n^(1/2)) * 8 bytes (per thread). Write that down, it's lowkey important π
π OPTIONS π
-c[NUM+],--count[=NUM+]β Count primes and/or prime k-tuplets,1 <= NUM <= 6. Count primes:-cor--count, count twin primes:-c2or--count=2, count prime triplets:-c3or--count=3, ... You can also count primes and prime k-tuplets at the same time, e.g.-c123counts primes, twin primes and prime triplets. multi-tasking queen π--cpu-infoβ Print CPU information: CPU name, frequency, number of cores, cache sizes, ... yes it's snooping on your hardware, but respectfully π΅οΈββοΈ-d,--dist=DISTβ Sieve the interval[START, START + DIST]. distance = the vibe check of where to stop β¨-h,--helpβ Print this help menu. the classic "help me help you" π«Ά-n,--nth-primeβ Find the nth prime, e.g.100 -nfinds the 100th prime. If 2 numbersN STARTare provided finds the nth prime> START, e.g.2 100 -nfinds the 2nd prime> 100. it's giving "which one? THAT one" π₯--no-statusβ Turn off the progressing status. no progress bar, no commentary, just silence π€«-p[NUM],--print[=NUM]β Print primes or prime k-tuplets,1 <= NUM <= 6. Print primes:-p, print twin primes:-p2, print prime triplets:-p3, ... the printer go brrr mode π¨οΈ-q,--quietβ Quiet mode, prints less output. introvert mode activated π-R,--RiemannRβ ApproximatePrimePi(x)using the Riemann R function:R(x). approximation slay, no cap β¨--RiemannR-inverseβ Approximate the nth prime using the inverse Riemann R function:R^-1(x). the remix version of the last one π-s,--size=SIZEβ Set the size of the sieve array in KiB,16 <= SIZE <= 8192. By defaultprimesieveuses a sieve size that matches your CPU's L1 cache size (per core) or is slightly smaller than your CPU's L2 cache size. This setting is crucial for performance β on exotic CPUsprimesievesometimes fails to determine the CPU's cache sizes which usually causes a big slowdown. In this case you can get a significant speedup by manually setting the sieve size to your CPU's L1 or L2 cache size (per core). it's literally measuring your cache, respect the hustle π-S,--stress-test[=MODE]β Run a stress test. TheMODEcan be eitherCPU(default) orRAM. TheCPUMODEuses little memory (< 5 MiBper thread) and puts the highest load on the CPU. TheRAMMODEon the other hand uses much more memory than theCPUMODE(each thread uses about1.16 GiB), but the CPU usually won't get as hot as in theCPUMODE. Stress testing keeps on running until either a miscalculation occurs (due to a hardware issue) or the timeout expires. The default timeout is 24 hours, the timeout can be changed using the--timeout=SECSoption. By default the stress test uses a number of threads that matches the number of CPU cores, the number of threads can be changed using the--threads=NUMoption. π₯ it's a workout for your computer, hydrate your CPU bestie π₯--testβ Run various correctness tests (< 1 minute). quick little quiz, you got this π-t,--threads=NUMβ Set the number of threads,1 <= NUM <= CPU cores. By defaultprimesieveuses all available CPU cores for counting primes and for finding the nth prime. invite the whole friend group π«Ά--timeβ Print the time elapsed in seconds. clock it β±οΈ--timeout=SECSβ Set the stress test timeout in seconds. Units of time for seconds, minutes, hours, days and years are also supported with the suffixs,m,h,dory. E.g.--timeout 10msets a timeout of 10 minutes. The default stress test timeout is 24 hours. so many ways to say "we're done here" β-v,--versionβ Print version and license information. the receipts, the paperwork, the whole legal moment π
π EXAMPLES π
primesieve 1000β Count the primes<= 1000. baby's first prime count πprimesieve 1e6 --printβ Print the primes<= 10^6. a million primes, no big deal πprimesieve 1e6 --print > primes.txtβ Store the primes<= 10^6in a text file. save it for later, bestie πΎprimesieve 2^32 --print=2β Print the twin primes<= 2^32. twins! iconic duo energy π―ββοΈprimesieve 1e16 --dist=1e10 --threads=1β Count the primes inside[10^16, 10^16 + 10^10]using a single thread. solo mission, single-threaded queen π
π§ HOMEPAGE π§
https://github.com/kimwalisch/primesieve
go follow the repo, it's giving star-worthy β
π AUTHOR π
Kim Walisch <kim.walisch@gmail.com> β legend behaviour, honestly π
ok that's the whole page, you read it all, I'm so proud ππ now go count some primes and remember: the sieve is segmented, the vibes are immaculate.
signed, sealed, delivered by your fave β page dated 02/17/2024, part of the primesieve 1 β¨ see you in the man pages, bestie π
π¦ where this page comes from
- arch rolling: primesieve 12.16-1 Β· BSD-2-Clause
- nixpkgs unstable: primesieve 12.14
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms