Prime[n]
gives the n
prime number
.
Prime
Prime[n]
gives the n
prime number
.
Details
- Prime is also known as prime number sequence.
- Integer mathematical function, suitable for both symbolic and numerical manipulation.
is the smallest positive integer greater than
, which cannot be divided by any integer greater than 1 and smaller than itself. The first prime
is the integer 2.
is asymptotically equivalent to
as
.
Examples
open all close allBasic Examples (3)
Scope (10)
Numerical Evaluation (4)
Symbolic Manipulation (6)
TraditionalForm formatting:
Prime[n]//TraditionalFormFind a solution instance of equalities with Prime:
FindInstance[Prime[n] + 2 == Prime[n + 1], n, Integers]Sum[1 / Prime[n] ^ s, {n, Infinity}]Product[1 + 1 / Prime[n] ^ s, {n, Infinity}]Recognize the Prime sequence:
FindSequenceFunction[{2, 3, 5, 7, 11, 13, 17, 19, 23, 29}, n]FullSimplify[Prime[n] > n Log[n], n∈Integers && n > 0]Find the leading asymptotic term for Prime as
approaches Infinity:
DiscreteAsymptotic[Prime[n], n -> ∞]The ratio of the sequence and its leading asymptotic approaches 1 as
approaches Infinity:
DiscreteLimit[Prime[n] / (n Log[n]), n -> ∞]Applications (38)
Basic Applications (9)
Multicolumn[If[PrimeQ[#], Framed[Style[#, Red]], #]& /@ Range[70], ...]Visualize the primes with a parabolic sieve:
Plot[{x^(1/2), -x^(1/2)}, {x, 0, 10}, Sequence[...]]Visualize the sieve of Eratosthenes for the first 5 primes:
Plot[Evaluate[Table[Prime[n] * Sin[x * Pi / Prime[n]], {n, 5}]], {x, 0, 30}]ListPolarPlot[Table[{Mod[π / 2 - n 4π / 20, 2π], Prime[n]}, {n, 20}], Sequence[...]]hexagonalSpiral[n_] := {Re[#], Im[#]}& /@ Fold[Join[#1, Last[#1] + Exp[I Pi / 3] ^ #2Range[#2 / 2]]&, {0}, Range[n]]spiral = hexagonalSpiral[25];primes = spiral[[Prime[Range[PrimePi[Length[spiral]]]]]];ListPlot[spiral, ...]Find the lowest-divisor pair for an integer
:
firstDivisorPair[n_Integer] :=
If[n == 1, 1, (If[PrimeQ[#[[1]]], #[[1]], #[[1]][#[[2]], Divide@@#]]&)[NestWhile[MapAt[NextPrime, #, 2]&, {n, 2}, !IntegerQ[Divide@@#]&]]]firstDivisorPair[24]Find the factorization for an integer
:
trialByDivision[n_Integer] :=
First[FixedPoint[MapAt[firstDivisorPair, #, Last[Position[#, _Integer, Heads -> False]]]&, {n}]]trialByDivision[24]Construct a factorization tree for an integer
:
factorTree[n_Integer] := TreeForm[trialByDivision[n], Rule[...]]factorTree[24]GraphPlot[Table[If[PrimeQ[(n/m)], 1, 0], {m, 11}, {n, 11}], ...]Visualize prime numbers with periodic curves. Prime numbers are those where only two curves cross—its own and the curve of 1:
labels = Table["" <> ToString[i], {i, 1, 10}];Plot[{Tooltip[-Sin[Pi * x], "1"], Evaluate[Table[Tooltip[n * Sin[Pi * x / n], labels[[n]]], {n, 2, 10}]]}, {x, 1, 10}, Sequence[...]]ArrayPlot[Partition[(PrimeQ[#1]&) /@ Table[i, {i, 1000}] /. {False -> 0, True -> 1}, Ceiling[Sqrt[1000]]], Rule[...]]Approximations (3)
Prime[25]25 * Log[25.]Plot Prime compared with an estimate:
ListStepPlot[{Table[Prime[n], {n, 25}], Table[n Log[n], {n, 25}]}]ListPlot[Table[Prime[n] / (n Log[n]), {n, 2, 5000}]]cesaro[n_] := Floor[n * (Log[n] + Log[Log[n]] - 1 + (Log[Log[n]] - 2) / Log[n] - (Log[Log[n]] ^ 2 - 6Log[Log[n]] + 11) / (2 * Log[n] ^ 2))]cesaro[2 10 ^ 15]Prime[2 10 ^ 15]Compute Prime using the aliquot sum
, which is equal to 1 when
is prime:
primeNumbers = Position[Table[DivisorSigma[1, n] - n, {n, 1, 100}], 1][[All, 1]]Table[Prime[n], {n, 1, PrimePi[100]}]Number Theory (14)
Mod[Array[Prime, 100], 10]ListLinePlot[Mod[Array[Prime, 100], 10]]ListLinePlot[Table[Mod[Prime[n + 1], n], {n, 1, 100}]]Plot of the first 50 primes modulo 6:
DiscretePlot[Mod[Prime[n], 6], {n, 50}]Fraction of the first million primes greater than 3 of the form
:
Count[Prime[Range[3, 1000002]], p_ /; Mod[p, 6] == 1] / 1000000With the exception of 2 and 3, all primes are of the form
:
% + Count[Prime[Range[3, 1000002]], p_ /; Mod[p, 6] == 5] / 1000000Define a residue number system:
modulus = {Prime[100], Prime[101], Prime[102], Prime[103]};Choose two numbers and represent them in the residue system:
a = 1234587;
b = 1423;remaindera = Mod[a, modulus]remainderb = Mod[b, modulus]Multiplying and recovering in the residue system:
ChineseRemainder[remaindera remainderb, modulus]a bChineseRemainder[remaindera + remainderb, modulus]a + bAn approximation to the zeta function:
1 / Product[1 - 1 / Prime[n] ^ s, {n, 6}]% /. s -> 2N[%]N[Zeta[2]]Calculate the probability that a number is relatively prime to the first 25 primes:
N[Last[FoldList[Times, 1, 1 - (1/Prime[Range[25]])]]100]ListPlot[FoldList[Times, 1, 1 - (1/Prime[Range[25]])], Rule[...]]Differences between the first 100 primes:
DiscretePlot[Prime[n + 1] - Prime[n], {n, 1, 100}]Find the jumping champion, i.e. the most frequently occurring difference between consecutive primes:
jumpingChampion = Commonest[Table[Prime[n + 1] - Prime[n], {n, 1, 100}]]Calculate the sum of prime factors:
sumPrimeFactors[n_] := Plus@@Flatten[Table[#1, {#2}]&@@@FactorInteger[n]]sumPrimeFactors[25]Plot the sum of prime factors for the first 25 integers:
ListStepPlot[sumPrimeFactors /@ Range[25]]Find Goldbach partitions, i.e. pairs of primes (
,
) such that
:
GoldbachPartitions[n_] := IntegerPartitions[2n, {2}, Prime@Range@PrimePi[2n]]GoldbachPartitions[50]Graph Goldbach's conjecture/comet:
ListPlot[Transpose[{Range[4, 1000, 2], Length /@ Table[IntegerPartitions[i, 2, Table[Prime[n], {n, PrimePi[i]}]], {i, 4, 1000, 2}]}], AxesOrigin -> {0, 0}]Calculate the primorial up to the nthprime, i.e. a function that multiplies successive primes, similar to the factorial:
primorial[0] := 1
primorial[1] := 2
primorial[n_] := Times@@Prime@Range[n];primorial[5]Compare the primorial to the factorial up to
:
DiscretePlot[{Log[n!], Log[Times@@Prime[Range[PrimePi[n]]]]}, {n, 1, 50}]Plot the differences between the factorial and the primorial up to
:
ListLinePlot[If[True, Differences, Identity][Table[Log[(n!/Times@@Prime[Range[PrimePi[n]]])], {n, 1, 100, 1}]], Rule[...]]Plot the Chebyshev theta function:
chebyshevTheta[n_] := Log[primorial[PrimePi[n]]];Plot[chebyshevTheta[n], {n, 1, 100}]Calculate the prime powers up to
:
primePowers[n_] := Union@@Table[Prime[Range[PrimePi[n ^ (1 / x)]]] ^ x, {x, Log2[n]}]primePowers[10]PrimePowerQ[%]Count all the prime powers up to
:
primePowerPi[n_] := PrimePi[n] + Sum[Floor@Log[Prime[k], n] - 1, {k, PrimePi[Sqrt[n]//Floor]}]primePowerPi[10]Graph the sequence of prime powers:
DiscretePlot[primePowerPi[n], {n, 1, 100}]It is conjectured that for any integer
, there is a prime
with
:
n = RandomInteger[500]n < NextPrime[n] < 2nVerify this for a range of integers:
AllTrue[Table[n < NextPrime[n] < 2n, {n, 2, 200}], #&]Plot Andrica's conjecture, which states that √pn+1-√pn<1 for every pair of consecutive prime numbers pn and pn+1:
ListStepPlot[-Subtract@@@Partition[Sqrt /@ Prime[Range[100]], 2, 1], Rule[...]]Plot Brocard's conjecture, which states that if pn and pn+1 are consecutive primes greater than 2, then between (pn)2 and (pn+1)2 there are at least four prime numbers:
ListStepPlot[-Subtract@@@Partition[PrimePi[Prime[Range[100]] ^ 2], 2, 1], Rule[...]]Plot polynomials for
-gons, i.e. Chebyshev polynomials of the second kind, such that
is prime:
Table[Plot[Evaluate[Table[Factor[ChebyshevU[Prime[n] - 1, x] / (GCD@@CoefficientList[ChebyshevU[Prime[n] - 1, x], x])][[k]], {k, 1, Length[Factor[ChebyshevU[Prime[n] - 1, x] / (GCD@@CoefficientList[ChebyshevU[Prime[n] - 1, x], x])]]}]], {x, -1, 1}], {n, 3, 6}]Special Sequences (12)
Find twin primes, i.e. pairs of primes of the form
:
Select[Table[If[PrimeQ[n + 2], n], {n, 2, 100}], PrimeQ]ListStepPlot[Select[Table[If[PrimeQ[n + 2], n], {n, 2, 100}], PrimeQ]]A prime
is a Sophie Germain prime if
is also a prime:
Multicolumn[If[PrimeQ[2 * Prime[#] + 1], Framed[Style[Prime[#], Red]], Prime[#]]& /@ Range[42], ...]MersennePrimeExponentQ[Prime[4]]PrimeQ[2 ^ Prime[4] - 1]There are 5 Fermat primes, i.e. Fermat numbers
such that
is prime:
Select[Table[2^2^n + 1, {n, 0, 4}], PrimeQ]There are two Wieferich primes under
, i.e. a prime number
such that
divides
:
Select[Range[10 ^ 4], Mod[2 ^ (# - 1) - 1, # ^ 2] == 0 && PrimeQ[#]&]Construct prime Euclid numbers:
Select[Table[Product[Prime[n], {n, m}] + 1, {m, 100}], PrimeQ]perfectNumbers = Select[Table[If[PrimeQ[(2 ^ Prime[n]) - 1], (2 ^ (Prime[n] - 1))((2 ^ Prime[n]) - 1)], {n, 1, 25}], IntegerQ]Pythagorean primes can be written as the sum of two squares, i.e. a prime number
:
Select[Table[If[Mod[Prime[n], 4] == 1, Prime[n]], {n, 1, 15}], IntegerQ]PowersRepresentations[13, 2, 2]13 == 2^2 + 3^2Ramanujan primes are the smallest number Rn such that π(x) - π(x/2) ≥ n for all x≥ Rn:
list = Table[PrimePi[n] - PrimePi[n / 2], {n, 10 ^ 4}];ramanujanPrime[n_] := 1 + Last[Position[list, n - 1]][[1]]ramanujanPrime[10]Differences in nth Ramanujan primes and Prime:
DiscretePlot[{ramanujanPrime[n], Prime[n]}, {n, 1, 50}]Primes of the form
, i.e. prime elements of the Gaussian integers:
Select[Table[If[PrimeQ[Prime[n], GaussianIntegers -> True], Prime[n]], {n, 1, 25}], PrimeQ]Array plot of the Gaussian primes, a Gaussian integer
such that if
and
are nonzero, then
is prime or if
,
or if
,
:
ArrayPlot[Table[If[PrimeQ[x + I y, GaussianIntegers -> True], If[1 ≠ 1 && !CoprimeQ[x + I y, 1], 2, 1], 0], {x, -25, 25}, {y, -25, 25}], Rule[...]](*or this version*)ArrayPlot[Array[Boole[PrimeQ[Complex@##, GaussianIntegers -> True]]&, {65, 65}, -32], Rule[...]]Emirp primes are primes
whose reversal is also prime but not a palindrome:
emirpPrimes = Select[Table[If[PrimeQ[If[IntegerReverse@Prime[n] ≠ Prime[n], IntegerReverse@Prime[n]]], Prime[n]], {n, 1, 20}], IntegerQ]IntegerReverse[%]PrimeQ[%]Find home primes of
.
is found by concatenating the prime factors of
and repeating until a prime is reached:
concatenatePrimes[n_] := FromDigits[Flatten[IntegerDigits /@ Flatten[Table[#1, {#2}]&@@@FactorInteger[n]]]];concatenatePrimes[9]PrimeQ[%]homePrime[n_] := NestWhile[concatenatePrimes[#]&, n, !PrimeQ[#]&];homePrime[1] = 1;homePrime[9]PrimeQ[%]Properties & Relations (8)
The traditional mathematical notation for Prime:
Prime[n]//TraditionalFormPrimes represents the domain of all prime numbers:
Element[Prime[30], Primes]The largest domain of definitions of Prime:
FunctionDomain[Prime[n], n]Prime is asymptotically equivalent to
as
:
DiscreteAsymptotic[Prime[n], n -> ∞]PrimePi is the inverse of Prime:
PrimePi[Prime[100]]Use NextPrime to find the next prime above n:
NextPrime[30]Prime[PrimePi[30] + 1]PrimeOmega counts the number of prime divisors:
PrimeOmega[Prime[5]]Divisors[Prime[5]]EulerPhi[n] counts numbers less than or equal to
that are coprime to
:
EulerPhi[Prime[10]]Prime[10] - 1Possible Issues (1)
Interactive Examples (2)
Visualize factorization diagrams:
Manipulate[Graphics[shapes[n], PlotRange -> {{-30, 30}, {-30, 30}}], {n, 1, 20, 1}, ...]Manipulate[ListPolarPlot[Table[{p, p}, {p, Table[Prime[n], {n, a}]}], ColorFunction -> "Rainbow", ImageSize -> Medium], {a, 100, 1000, 10}]Neat Examples (6)
Ulam spiral colored based on the difference in Prime values:
ulam[n_] := Partition[Permute[Range[n ^ 2], Accumulate[Take[Flatten[{{n ^ 2 + 1} / 2, Table
[(-1) ^ j i, {j, n}, {i, {-1, n}}, {j}]}], n ^ 2]]], n]ArrayPlot[Prime[ulam[101] + 1] - Prime[ulam[101]], Rule[...]]Visualize when
is divisible by primes. Each row of dots corresponds to the divisors of
, which are labelled along the horizontal axis:
NumberLinePlot[Table[Select[Range[Prime[n]], (Divisible[Prime[n] - 1, #] && # > 1 && PrimeQ[#])&], {n, 1, 40}], PlotRange -> All]Generate a path based on the Prime sequence:
Graphics[Line[AnglePath[Table[Prime[n], {n, 1, 1000}]], Rule[...]]]Construct polyhedra using directed graphs generated by primes less than
:
vertexcoords[p_] := GraphEmbedding[Graph3D[Flatten@Table[i -> Mod[i q, p], {i, 1, p - 1}, {q, Prime[Range[PrimePi[p] - 1]]}]]];Table[ConvexHullMesh[vertexcoords[p], Rule[...]], {p, Prime[Range[4, 7]]}]Visualize prime
-sided polygons:
Table[Graphics[{EdgeForm[StandardGray], Riffle[RandomColor@50, Polygon /@ (CirclePoints[#, 1, Prime[n]]& /@ Tuples[Range@1, {2}])]}], {n, 2, 5}]Fill the set of primes with primes:
WordCloud[Table[Prime[n], {n, 1, 100}], [image]]See Also
NextPrime RandomPrime PrimeQ PrimePowerQ CompositeQ PrimePi Primes PrimeZetaP Zeta MersennePrimeExponent FactorInteger PerfectNumber EulerPhi
Function Repository: LargestPrimeGap TwinPrimes TwinPrime
History
Introduced in 1988 (1.0) | Updated in 2020 (12.1)
Text
Wolfram Research (1988), Prime, Wolfram Language function, https://reference.wolfram.com/language/ref/Prime.html (updated 2020).
CMS
Wolfram Language. 1988. "Prime." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/Prime.html.
APA
Wolfram Language. (1988). Prime. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Prime.html
BibTeX
@misc{reference.wolfram_2026_prime, author="Wolfram Research", title="{Prime}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/Prime.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_prime, organization={Wolfram Research}, title={Prime}, year={2020}, url={https://reference.wolfram.com/language/ref/Prime.html}, note=[Accessed: 13-June-2026]}