PRIMESIEVE(1) | PRIMESIEVE(1) |

# NAME

primesieve - generate prime numbers

# 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. primesieve includes a number of extensions to the sieve of
Eratosthenes which significantly improve performance: multiples of small
primes are pre-sieved, it uses wheel factorization to skip multiples with
small prime factors and 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.

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).

# OPTIONS

**-c**[*NUM+*], **--count**[=*NUM+*]

*NUM*<= 6. Count primes:

**-c**or

**--count**, count twin primes:

**-c2**or

**--count=2**, count prime triplets:

**-c3**or

**--count=3**, ... You can also count primes and prime k-tuplets at the same time, e.g.

**-c123**counts primes, twin primes and prime triplets.

**--cpu-info**

**-d, --dist**=*DIST*

*START*,

*START*+

*DIST*].

**-h, --help**

**-n, --nth-prime**

**-n**finds the 100th prime. If 2 numbers

*N*

*START*are provided finds the nth prime >

*START*, e.g. 2 100

**-n**finds the 2nd prime > 100.

**--no-status**

**-p**[*NUM*], **--print**[=*NUM*]

*NUM*<= 6. Print primes:

**-p**, print twin primes:

**-p2**, print prime triplets:

**-p3**, ...

**-q, --quiet**

**-s, --size**=*SIZE*

*SIZE*<= 8192. By default primesieve uses 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 CPUs primesieve sometimes 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).

**--test**

**-t, --threads**=*NUM*

*NUM*<= CPU cores. By default primesieve uses all available CPU cores for counting primes and for finding the nth prime.

**--time**

**-v, --version**

# EXAMPLES

**primesieve 1000**

**primesieve 1e6 --print**

**primesieve 1e6 --print > primes.txt**

**primesieve 2^32 --print=2**

**primesieve 1e16 --dist=1e10 --threads=1**

# HOMEPAGE

# AUTHOR

Kim Walisch <kim.walisch@gmail.com>

12/02/2022 |