Navigation

Operators and Keywords

Function List:

C++ API

: primes (n)

Return all primes up to n.

The output data class (double, single, uint32, etc.) is the same as the input class of n. The algorithm used is the Sieve of Eratosthenes.

Notes: If you need a specific number of primes you can use the fact that the distance from one prime to the next is, on average, proportional to the logarithm of the prime. Integrating, one finds that there are about k primes less than k*log (5*k).

See also list_primes if you need a specific number n of primes.

See also: list_primes, isprime.

Package: octave