A031131 Difference between n-th prime and (n+2)-nd prime.
3, 4, 6, 6, 6, 6, 6, 10, 8, 8, 10, 6, 6, 10, 12, 8, 8, 10, 6, 8, 10, 10, 14, 12, 6, 6, 6, 6, 18, 18, 10, 8, 12, 12, 8, 12, 10, 10, 12, 8, 12, 12, 6, 6, 14, 24, 16, 6, 6, 10, 8, 12, 16, 12, 12, 8, 8, 10, 6, 12, 24, 18, 6, 6, 18, 20, 16, 12, 6, 10, 14, 14, 12, 10, 10, 14, 12, 12, 18, 12, 12, 12
Offset: 1
Keywords
Examples
a(10)=8 because the 10th prime=29 is followed by primes 31 and 37, and 37 - 29 = 8.
Links
- T. D. Noe, Table of n, a(n) for n = 1..10000
- D. H. J. Polymath, Variants of the Selberg sieve, and bounded intervals containing many primes, Research in the Mathematical Sciences 1:12 (2014).
- Polymath project, Bounded gaps between primes
Crossrefs
Programs
-
Haskell
a031131 n = a031131_list !! (n-1) a031131_list = zipWith (-) (drop 2 a000040_list) a000040_list -- Reinhard Zumkeller, Dec 19 2013
-
Magma
[NthPrime(n+2)-NthPrime(n): n in [1..100] ]; // Vincenzo Librandi, Apr 11 2011
-
Maple
P:= select(isprime, [2,seq(2*i+1,i=1..1000)]): P[3..-1] - P[1..-3]; # Robert Israel, Jan 25 2015
-
Mathematica
Differences[lst_]:=Drop[lst,2]-Drop[lst,-2]; Differences[Prime[Range[123]]] (* Vladimir Joseph Stephan Orlovsky, Aug 13 2009 *) Map[#3 - #1 & @@ # &, Partition[Prime@ Range[84], 3, 1]] (* Michael De Vlieger, Dec 17 2017 *)
-
MuPAD
ithprime(i+2)-ithprime(i) $ i = 1..65 // Zerinvary Lajos, Feb 26 2007
-
PARI
a(n)=my(p=prime(n));nextprime(nextprime(p+1)+1)-p \\ Charles R Greathouse IV, Jul 01 2013
-
Sage
BB = primes_first_n(67) L = [] for i in range(65): L.append(BB[2+i]-BB[i]) L # Zerinvary Lajos, May 14 2007
Formula
a(n) = 2*A052288(n-1) for n>1. - Hugo Pfoertner, Apr 16 2025
Extensions
Corrected by T. D. Noe, Sep 11 2008
Edited by N. J. A. Sloane, Sep 18 2008, at the suggestion of T. D. Noe
Comments