Learn R Programming

gmp (version 0.7-5)

nextprime: Next Prime Number

Description

Return the next prime number, say \(p\), with \(p > n\).

Usage

nextprime(n)

Value

A (probably) prime number

Arguments

n

Integer

Author

Antoine Lucas

Details

This function uses probabilistic algorithm to identify primes. For practical purposes, it is adequate, the chance of a composite passing will be extremely small.

References

The GNU MP Library, see https://gmplib.org

See Also

isprime and its references and examples.

Examples

Run this code
nextprime(14)
## still very fast:
(p <- nextprime(1e7))
## to be really sure { isprime()  gives "probably prime" } :
stopifnot(identical(p, factorize(p)))

Run the code above in your browser using DataLab