numbers (version 0.7-5)

nextPrime: Next Prime

Description

Find the next prime above n.

Usage

nextPrime(n)

Arguments

n

natural number.

Value

Integer.

Details

nextPrime finds the next prime number greater than n, while previousPrime finds the next prime number below n. In general the next prime will occur in the interval [n+1,n+log(n)].

In double precision arithmetic integers are represented exactly only up to 2^53 - 1, therefore this is the maximal allowed value.

See Also

Primes, isPrime

Examples

Run this code
# NOT RUN {
p <- nextPrime(1e+6)  # 1000003
isPrime(p)            # TRUE
# }

Run the code above in your browser using DataLab