Eratosthenes resp. Atkin sieve methods to generate a list of prime numbers
less or equal n
, resp. between n1
and n2
.
Primes(n1, n2 = NULL) atkin_sieve(n)
vector of integers representing prime numbers
natural numbers with n1 <= n2
.
The list of prime numbers up to n
is generated using the "sieve of
Eratosthenes". This approach is reasonably fast, but may require a lot of
main memory when n
is large.
Primes
computes first all primes up to sqrt(n2)
and then
applies a refined sieve on the numbers from n1
to n2
, thereby
drastically reducing the need for storing long arrays of numbers.
The sieve of Atkins is a modified version of the ancient prime number sieve of Eratosthenes. It applies a modulo-sixty arithmetic and requires less memory, but in R is not faster because of a double for-loop.
In double precision arithmetic integers are represented exactly only up to 2^53 - 1, therefore this is the maximal allowed value.
A. Atkin and D. Bernstein (2004), Prime sieves using quadratic forms. Mathematics of Computation, Vol. 73, pp. 1023-1030.
isPrime
, gmp::factorize
, pracma::expint1