Wolfram Research

Function Repository Resource:

LargestPrimeGap

Source Notebook

Give the greatest gap between the primes up to the argument

Contributed by: Wolfram Staff

ResourceFunction["LargestPrimeGap"][arg]

gives the largest difference between primes up to arg, which must be at least 3.

Examples

Basic Examples

Here are the primes up to 13:

In[1]:=
Prime /@ Range@PrimePi@13
Out[1]=

The largest gap is between 7 and 11:

In[2]:=
ResourceFunction["LargestPrimeGap"][13]
Out[2]=

The function is nondecreasing:

In[3]:=
ListLinePlot[ResourceFunction["LargestPrimeGap"] /@ Range[1000]]
Out[3]=

Although the gaps are unbounded, they rise slowly:

In[4]:=
Map[ResourceFunction["LargestPrimeGap"], 10^Range[7]]
Out[4]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information