Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Mathematics and Algorithms > Number Theory > Prime Numbers >
Mathematica > Mathematics and Algorithms > Mathematical Functions > Number Theoretic Functions > Prime Numbers >

NextPrime

NextPrime[n]
gives the next prime above n.
NextPrime[n, k]
gives the k^(th) prime above n.
  • The number k can be negative, giving previous primes.
  • The number n need not be an integer, and can be negative.  »
The next prime after a million:
The last prime before a million:
The next prime after a million:
In[1]:=
Click for copyable input
Out[1]=
 
The last prime before a million:
In[1]:=
Click for copyable input
Out[1]=
NextPrime allows real numbers as arguments:
Arguments can be negative:
A negative second argument gives previous primes:
Plot prime gaps around powers of 10:
Find twin primes:
New in 6
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team