PRIMES

Purpose:

Generates a series of primes numbers in ascending order.

Syntax:

PRIMES(n, "count", "nth", "silent")

n

-

An integer, the maximum prime value. The returned series contains prime numbers less than or equal to n.

"count"

-

Optional. A string. If specified, only return the count of primes <= n. Defaults to return the full series of prime values.

"nth"

-

Optional. A string. If specified, only return the nth prime <= n. Defaults to return the full series of prime values.

"silent"

-

Optional. A string. If specified, operate without status messages. Defaults to "verbose", show status messages.

Alternate Syntax:

PRIMES(pmin, pmax, "count", "nth", "silent")

pmin

-

An integer, the minimum prime value. The returned series contains prime numbers greater than or equal to pmin.

pmax

-

An integer, the maximum prime value. The returned series contains primes less than or equal to pmax.

"count"

-

Optional. A string. If specified, only return the count of primes >= pmin and primes <= pmax. Defaults to return a series of prime values within the range.

"nth"

-

Optional. A string. If specified, only return the nth prime <= pmax. The value of pmin is ignored. Defaults to return the series of prime values within the range.

"silent"

-

Optional. A string. If specified, operate without status messages. Defaults to "verbose", show status messages.

Returns:

A series, the prime values less than or equal to n.

Example:

W1: primes(10)

 

W1 contains the series {2, 3, 5, 7}.

Example:

W1: primes(10, "count")

 

returns 4 indicating there are 4 prime values less than or equal to 10.

Example:

W1: primes(4, "nth")

 

returns 7, the fourth prime.

Example:

W1: primes(10)

W2: isprime(W1)

 

W2 contains the series {1, 1, 1, 1}, indicating that all the values of W1 are prime.

Example:

W1: primes(10, 20)

 

W1 contains the series {11, 13, 17, 19}, the primes values between 10 and 20.

Example:

W1: primes(10, 20, "count")

 

returns 4, indicating there are 4 prime values between 10 and 20.

Remarks:

A prime number is a natural number (positive integer) with exactly two divisors, 1 and itself. Thus, 0 and 1 are not prime.

 

PRIMES uses a segmented sieve of Eratosthenes algorithm with wheel factorization written by Kim Walisch licensed under the MIT License.

 

https://github.com/kimwalisch/primesieve

See Also:

FACTORS

ISPRIME