Generate a list of prime numbers less or equal n, resp. between
n1 and n2.
Usage
primes(n)
primes2(n1, n2)
Arguments
n
nonnegative integer greater than 1.
n1, n2
natural numbers with n1 <= n2<="" code="">.=>
Value
vector of integers representing prime numbers
Details
The list of prime numbers up to n is generated using the "sieve of
Erasthostenes". This approach is reasonably fast, but may require a lot of
main memory when n is large.
primes2 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.
In double precision arithmetic integers are represented exactly only up to
2^53 - 1, therefore this is the maximal allowed value.