Function Repository Resource:

CousinPrimes

Source Notebook

Get the pairs of primes that differ by 4

Contributed by: Wolfram Staff

ResourceFunction["CousinPrimes"][n]

gives the first n pairs of primes that differ by 4.

Examples

Basic Examples (2) 

Here are the first 10 pairs of cousin primes:

In[1]:=
ResourceFunction["CousinPrimes"][10]
Out[1]=

Indeed, the differences are 4:

In[2]:=
Differences /@ %
Out[2]=

Neat Examples (3) 

The sum of the reciprocals of the primes diverges:

In[3]:=
Sum[1/Prime@n, {n, \[Infinity]}]
Out[3]=

The sum of the reciprocals of the cousin primes converges to a number around 1.673. Here is the sum of the reciprocals of the first 100,000 cousin primes:

In[4]:=
Total[1./Flatten@ResourceFunction["CousinPrimes"][10^5]]
Out[4]=

This is the last pair in that sum:

In[5]:=
Last@ResourceFunction["CousinPrimes"][10^5]
Out[5]=

Publisher

George Beck

Version History

  • 2.0.0 – 05 July 2019
  • 1.0.0 – 22 May 2019

Related Resources

License Information