NextPrime

NextPrime[x]

gives the smallest prime above x.

NextPrime[x,k]

gives the k^(th)-next prime above x.

Details

  • NextPrime is also known as previous prime.
  • Mathematical function, suitable for both symbolic and numerical manipulation.
  • For positive x, NextPrime[x] is the (m+1)^(th) prime number where m is the number of primes less than or equal to x.
  • NextPrime[x, k] is the (m+k)^(th) prime number where m is the number of primes less than or equal to x.

Examples

open allclose all

Basic Examples  (2)

Compute the next prime after 10:

Plot the sequence of primes:

Scope  (9)

Numerical Manipulation  (7)

NextPrime works over integers:

Rational numbers:

Real numbers:

Compute the last prime before 50:

Compute the second prime after 50:

NextPrime works over large integers:

NextPrime threads over lists:

Symbolic Manipulation  (2)

Find a solution instance of equalities with NextPrime:

Reduce an equation:

Applications  (15)

Basic Applications  (6)

Highlight the sequence of primes using NextPrime:

Visualize the primes with a parabolic sieve:

Visualize the sieve of Eratosthenes for the first 5 primes:

Spiral of a NextPrime sequence:

Hexagonal prime spiral using NextPrime:

Find the lowest-divisor pair for an integer :

Find the prime factorization for an integer :

Construct a factorization tree for an integer :

Approximations  (2)

Approximation to Prime:

Plot Prime compared with an estimate:

Compute Prime:

Number Theory  (5)

NextPrime numbers modulo 10:

NextPrime numbers modulo :

Plot prime gaps around powers of 10:

Visualize the gaps between primes below 104:

Plot a histogram of the closest distances to a prime for a range of integers:

Compare the NextPrime sequence to PrimePi:

It is conjectured that for any integer , there is a prime with :

Verify this for a range of integers:

Special Sequences  (2)

Find twin primes, i.e. pairs of primes of the form :

Plot the twin primes:

Compute the smallest n-digit prime:

Plot the difference between the smallest n-digit prime and :

Properties & Relations  (4)

Primes represents the domain of all primes numbers:

The largest domain of definitions of NextPrime:

Compute the prime using NextPrime:

Compute using PrimePi:

Neat Examples  (5)

Ulam spiral of the distance to the next prime:

Generate a path based on the NextPrime sequence:

Visualize the increase in prime numbers through -sided polygons:

Plot NextPrime using ArrayPlot:

Sunflower seed representation of NextPrime:

Introduced in 2007
 (6.0)
 |
Updated in 2020
 (12.1)