cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-10 of 20 results. Next

A031131 Difference between n-th prime and (n+2)-nd prime.

Original entry on oeis.org

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

Views

Author

Keywords

Comments

Distance between the pair of primes adjacent to the (n+1)-st prime. - Lekraj Beedassy, Oct 01 2004 [Typo corrected by Zak Seidov, Feb 22 2009]
A031131(A261525(n)) = 2*n and A031131(m) != 2*n for m < A261525(n). - Reinhard Zumkeller, Aug 23 2015
The Polymath project 8b proved that a(n) <= 395106 infinitely often (their published paper contains the slightly weaker bound a(n) <= 398130 infinitely often). - Charles R Greathouse IV, Jul 22 2016

Examples

			a(10)=8 because the 10th prime=29 is followed by primes 31 and 37, and 37 - 29 = 8.
		

Crossrefs

Sum of consecutive terms of A001223.
Cf. A075527 (allowing 1 to be prime).
First differences of A001043.

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) = A001223(n) + A001223(n-1). - Lior Manor, Jan 19 2005
a(n) = A000040(n+2) - A000040(n).
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

A051699 Distance from n to closest prime.

Original entry on oeis.org

2, 1, 0, 0, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 1, 0, 1, 0, 1
Offset: 0

Views

Author

Keywords

Examples

			Closest primes to 0,1,2,3,4 are 2,2,2,3,3.
		

Crossrefs

Programs

  • Maple
    A051699 := proc(n) if isprime(n) then 0; elif n<= 2 then 2-n ; else min(nextprime(n)-n, n-prevprime(n)) ; end if ; end proc; # R. J. Mathar, Nov 01 2009
  • Mathematica
    FormatSequence[ Table[Min[Abs[n-If[n<2, 2, Prime[{#, #+1}&[PrimePi[n]]]]]], {n, 0, 101}], 51699, 0, Name->"Distance to closest prime." ]
    (* From version 6 on: *) a[?PrimeQ] = 0; a[n] := Min[NextPrime[n]-n, n-NextPrime[n, -1]]; Table[a[n], {n, 0, 104}] (* Jean-François Alcover, Apr 05 2012 *)
  • PARI
    a(n)=if(n<1,2*(n==0),vecmin(vector(n,k,abs(n-prime(k)))))
    
  • PARI
    a(n)=if(n<1,2*(n==0),min(nextprime(n)-n,n-precprime(n)))
    
  • Python
    from sympy import prevprime, nextprime, isprime
    def A051699(n): return nextprime(n) - n if n <= 1 else 0 if isprime(n) else min(n-prevprime(n), nextprime(n)-n) # Ya-Ping Lu, Mar 22 2025

Formula

Conjecture: S(n) = Sum_{k=1..n} a(k) is asymptotic to C*n*log(n) with C=0.29...... - Benoit Cloitre, Aug 11 2002
C = lim_{n->oo} S(n)/(n*log(n)) = 0.44 approximately. - Ya-Ping Lu, Apr 06 2025
Comment from Giorgio Balzarotti, Sep 18 2005: by means of the Prime Number Theorem is possible to derive the following inequality: c1*n*log(n) < S(n) < c2*n*log(n), where c1 = 1/4 and c2 = 3/8 (for n > 130). For a more accurate estimation of the values for c1 and c2, it necessary to know the number of twin primes with respect to the total number of primes.
abs(a(n)-a(n+1)) = 1 if n != 2; a((p+q)/2 +- k) = (q-p)/2 - k, where p < q are two consecutive primes and k = 0, 1, 2, ..., (q-p)/2. - Ya-Ping Lu, Mar 22 2025

Extensions

More terms from James Sellers

A023186 Lonely (or isolated) primes: increasing distance to nearest prime.

Original entry on oeis.org

2, 5, 23, 53, 211, 1847, 2179, 3967, 16033, 24281, 38501, 58831, 203713, 206699, 413353, 1272749, 2198981, 5102953, 10938023, 12623189, 72546283, 142414669, 162821917, 163710121, 325737821, 1131241763, 1791752797, 3173306951, 4841337887, 6021542119, 6807940367, 7174208683, 8835528511, 11179888193, 15318488291, 26329105043, 31587561361, 45241670743
Offset: 1

Views

Author

Keywords

Comments

Erdős and Suranyi call these reclusive primes and prove that there are an infinite number of them. They define these primes to be between two primes. Hence their first term would be 3 instead of 2. Record values in A120937. - T. D. Noe, Jul 21 2006

Examples

			The nearest prime to 23 is 4 units away, larger than any previous prime, so 23 is in the sequence.
The prime a(4) = A120937(3) = 53 is at distance 2*3 = 6 from its neighbors {47, 59}. The prime a(5) = A120937(4) = A120937(5) = A120937(6) = 211 is at distance 2*6 = 12 from its neighbors {199, 223}. Sequence A120937 requires the terms to have 2 neighbors, therefore its first term is 3 and not 2. - _M. F. Hasler_, Dec 28 2015
		

References

  • Paul Erdős and Janos Suranyi, Topics in the theory of numbers, Springer, 2003.

Crossrefs

Programs

  • Mathematica
    p = 0; q = 2; i = 0; Do[r = NextPrime[q]; m = Min[r - q, q - p]; If[m > i, Print[q]; i = m]; p = q; q = r, {n, 1, 152382000}]
    Join[{2},DeleteDuplicates[{#[[2]],Min[Differences[#]]}&/@Partition[Prime[ Range[ 2,10^6]],3,1],GreaterEqual[ #1[[2]],#2[[2]]]&][[;;,1]]] (* The program generates the first 20 terms of the sequence. *) (* Harvey P. Dale, Aug 31 2023 *)

Extensions

More terms from Jud McCranie, Jun 16 2000
More terms from T. D. Noe, Jul 21 2006

A051697 Closest prime to n (break ties by taking the smaller prime).

Original entry on oeis.org

2, 2, 2, 3, 3, 5, 5, 7, 7, 7, 11, 11, 11, 13, 13, 13, 17, 17, 17, 19, 19, 19, 23, 23, 23, 23, 23, 29, 29, 29, 29, 31, 31, 31, 31, 37, 37, 37, 37, 37, 41, 41, 41, 43, 43, 43, 47, 47, 47, 47, 47, 53, 53, 53, 53, 53, 53, 59, 59, 59, 59, 61, 61, 61, 61, 67, 67, 67, 67, 67, 71, 71
Offset: 0

Views

Author

Keywords

Examples

			Closest primes to 0,1,2,3,4 are 2,2,2,3,3.
		

Crossrefs

Programs

  • Mathematica
    a[n_] := (np = NextPrime[n]; pp = Prime[PrimePi[np] - 1]; Which[np > 2n-pp, pp, np < 2n-pp, np, True, pp]); a[0] = a[1] = 2; Table[a[n], {n, 0, 71}] (* Jean-François Alcover, Jul 28 2011 *)
  • PARI
    a(n)=if(n<3, return(2)); my(p=precprime(n),q=nextprime(n)); if(q-nCharles R Greathouse IV, Apr 28 2015

Extensions

More terms from James Sellers

A051728 Smallest number at distance 2n from nearest prime.

Original entry on oeis.org

2, 0, 23, 53, 409, 293, 211, 1341, 1343, 2179, 3967, 15705, 16033, 19635, 31425, 24281, 31429, 31431, 31433, 155959, 38501, 58831, 203713, 268343, 206699, 370311, 370313, 370315, 370317, 1349591, 1357261, 1272749, 1357265, 1357267, 2010801, 2010803, 2010805, 2010807
Offset: 0

Views

Author

Keywords

Comments

a(0) = 2. For n > 0, let f(m) = minimal distance from m to closest prime (excluding m itself). The a(n) = min { m : f(m) = 2n }.
f(m) is tabulated in A051700. - R. J. Mathar, Nov 18 2007

Crossrefs

Programs

  • Maple
    A051700 := proc(m) if m <= 2 then op(m+1,[2,1,1]) ; else min(nextprime(m)-m,m-prevprime(m)) ; fi ; end: A051728 := proc(n) local m ; if n = 0 then RETURN(2); else for m from 0 do if A051700(m) = 2 * n then RETURN(m) ; fi ; od: fi ; end: seq(A051728(n),n=0..20) ; # R. J. Mathar, Nov 18 2007
  • Mathematica
    a[n_] := Module[{m}, If[n == 0, Return[2], For[m = 0, True, m++, If[Min[NextPrime[m]-m, m-NextPrime[m, -1]] == 2*n, Return[m]]]]]; Table[Print[an = a[n]]; an, {n, 0, 33}] (* Jean-François Alcover, Feb 11 2014, after R. J. Mathar *)
    Join[{2},With[{t=Table[{n,Min[n-NextPrime[n,-1],NextPrime[n]-n]},{n,0,1358000}]},Table[SelectFirst[t,#[[2]]==2k&],{k,33}]][[All,1]]] (* Harvey P. Dale, Aug 13 2019 *)

Formula

a(n) = A051652(2*n). - Sean A. Irvine, Oct 01 2021

Extensions

More terms from James Sellers, Dec 07 1999
More terms from Amiram Eldar, Aug 28 2021

A051652 Smallest number at distance n from nearest prime.

Original entry on oeis.org

2, 1, 0, 26, 23, 118, 53, 120, 409, 532, 293, 1140, 211, 1340, 1341, 1342, 1343, 1344, 2179, 15702, 3967, 15704, 15705, 19632, 16033, 19634, 19635, 31424, 31425, 31426, 24281, 31428, 31429, 31430, 31431, 31432, 31433, 155958, 155959, 155960, 38501
Offset: 0

Views

Author

Keywords

Crossrefs

Programs

  • Maple
    A051700 := proc(m) option remember ; if m <= 2 then op(m+1,[2,1,1]) ; else min(nextprime(m)-m,m-prevprime(m)) ; fi ; end:
    A051652 := proc(n) local m ; if n = 0 then RETURN(2); else for m from 0 do if A051700(m) = n then RETURN(m) ; fi ; od: fi ; end:
    for n from 0 to 79 do printf("%d %d\n",n,A051652(n)); od: # R. J. Mathar, Jul 22 2009
  • Mathematica
    A051700[n_] := A051700[n] = Min[ NextPrime[n] - n, n - NextPrime[n, -1]]; a[n_] := For[m = 0, True, m++, If[A051700[m] == n, Return[m]]]; a[0] = 2; Table[ a[n], {n, 0, 40}] (* Jean-François Alcover, Dec 19 2011, after R. J. Mathar *)
    Join[{2,1,0},Drop[Flatten[Table[Position[Table[Min[NextPrime[n]-n, n-NextPrime[ n,-1]],{n,200000}],?(#==i&),{1},1],{i,40}]],2]] (* _Harvey P. Dale, Mar 16 2015 *)
  • Python
    # see link for faster program
    from sympy import prevprime, nextprime
    def A051700(n):
      return [2, 1, 1][n] if n < 3 else min(n-prevprime(n), nextprime(n)-n)
    def a(n):
      if n == 0: return 2
      m = 0
      while A051700(m) != n: m += 1
      return m
    print([a(n) for n in range(26)]) # Michael S. Branicky, Feb 27 2021

Extensions

More terms from James Sellers, Dec 07 1999

A051702 Distance from n-th prime to closest prime.

Original entry on oeis.org

1, 1, 2, 2, 2, 2, 2, 2, 4, 2, 2, 4, 2, 2, 4, 6, 2, 2, 4, 2, 2, 4, 4, 6, 4, 2, 2, 2, 2, 4, 4, 4, 2, 2, 2, 2, 6, 4, 4, 6, 2, 2, 2, 2, 2, 2, 12, 4, 2, 2, 4, 2, 2, 6, 6, 6, 2, 2, 4, 2, 2, 10, 4, 2, 2, 4, 6, 6, 2, 2, 4, 6, 6, 6, 4, 4, 6, 4, 4, 8, 2, 2, 2, 2, 4, 4, 6, 4, 2, 2, 4, 8, 4, 4, 4, 4, 6, 2, 2, 6, 6, 6, 6, 2
Offset: 1

Views

Author

Keywords

Examples

			Closest primes to 2,3,5,7,11 are 3,2,3,5,13.
		

Crossrefs

Programs

  • Mathematica
    a[n_] := Min[(p = Prime[n]) - NextPrime[p, -1], NextPrime[p] - p]; Table[a[n], {n, 1, 104}] (* Jean-François Alcover, May 27 2013 *)
    Join[{1},Min[Differences[#]]&/@Partition[Prime[Range[110]],3,1]] (* Harvey P. Dale, Sep 23 2016 *)
  • PARI
    a(n,p=prime(n))=min(p-precprime(p-1),nextprime(p+1)-p) \\ Charles R Greathouse IV, Feb 06 2017

Extensions

More terms from James Sellers

A023188 Lonely (or isolated) primes: least prime of distance n from nearest prime (n = 1 or even).

Original entry on oeis.org

2, 5, 23, 53, 409, 293, 211, 1847, 3137, 2179, 3967, 23719, 16033, 40387, 44417, 24281, 158699, 220973, 172933, 321509, 38501, 58831, 203713, 268343, 206699, 829399, 824339, 413353, 2280767, 2305549, 3253631, 1272749, 2401807, 2844833, 3021241
Offset: 1

Views

Author

Keywords

Comments

a(1)=least prime of distance 1 from nearest prime.
if n>1 a(n)=least prime of distance 2n-2 from nearest prime.

Crossrefs

Programs

  • Mathematica
    NextPrim[n_] := Block[{k = n + 1}, While[ !PrimeQ[k], k++ ]; k]; a = Table[0, {35}]; p = 2; q = 3; k = 1; Do[r = NextPrim[q]; m = Min[r - q, q - p]/2; If[m < 35 && a[[m]] == 0, a[[m]] = q]; p = q; q = r, {n, 1, 235000}]
    Join[{2},Transpose[Flatten[Table[Select[Partition[Prime[ Range[ 1000000]],3,1], Min[ Differences[#]] == 2n&,1],{n,40}],1]][[2]]](* Harvey P. Dale, Nov 17 2013 *)

Extensions

a(36)-a(65) from Daniel Lignon, Aug 07 2015

A046929 Width of moat of composite numbers surrounding n-th prime.

Original entry on oeis.org

0, 0, 1, 1, 1, 1, 1, 1, 3, 1, 1, 3, 1, 1, 3, 5, 1, 1, 3, 1, 1, 3, 3, 5, 3, 1, 1, 1, 1, 3, 3, 3, 1, 1, 1, 1, 5, 3, 3, 5, 1, 1, 1, 1, 1, 1, 11, 3, 1, 1, 3, 1, 1, 5, 5, 5, 1, 1, 3, 1, 1, 9, 3, 1, 1, 3, 5, 5, 1, 1, 3, 5, 5, 5, 3, 3, 5, 3, 3, 7, 1, 1, 1, 1, 3, 3, 5, 3, 1, 1, 3, 7, 3, 3
Offset: 1

Views

Author

Keywords

Examples

			23 has a buffer of 3 composites around it on each side: 20,21,22,23,24,25,26.
		

Crossrefs

Programs

  • Maple
    with(numtheory); a := i->min(ithprime(n)-ithprime(n-1)-1, ithprime(n+1)-ithprime(n)-1);
  • Mathematica
    a[n_] := Min[Prime[n] - Prime[n-1] - 1, Prime[n+1] - Prime[n] - 1]; a[1] = 0; Table[a[n], {n, 1, 100}] (* Jean-François Alcover, Apr 16 2013 *)
    Join[{0},Min[Differences[#]]&/@Partition[Prime[Range[100]],3,1]-1] (* Harvey P. Dale, Feb 24 2014 *)

A051650 Lonely numbers: distance to closest prime sets a new record.

Original entry on oeis.org

0, 23, 53, 120, 211, 1340, 1341, 1342, 1343, 1344, 2179, 3967, 15704, 15705, 16033, 19634, 19635, 24281, 31428, 31429, 31430, 31431, 31432, 31433, 38501, 58831, 155964, 203713, 206699, 370310, 370311, 370312, 370313, 370314, 370315, 370316
Offset: 0

Views

Author

Keywords

Examples

			23 is 4 units away from the closest prime (not including itself), so 23 is in the sequence.
		

Crossrefs

Distances are in A051730.

Programs

  • Mathematica
    d[0] = 2; d[k_] := Min[k - NextPrime[k, -1], NextPrime[k] - k]; a[0] = 0; a[n_] := a[n] = (k = a[n-1] + 1; record = d[a[n-1]]; While[d[k] <= record, k++]; k); Table[a[n], {n, 0, 35}] (* Jean-François Alcover, Jan 16 2012 *)
    dcp[n_]:=Min[n-NextPrime[n,-1],NextPrime[n]-n]; DeleteDuplicates[Table[{n,dcp[n]},{n,0,375000}],GreaterEqual[#1[[2]],#2[[2]]]&][[;;,1]] (* Harvey P. Dale, Feb 23 2023 *)
  • PARI
    print1(0);w=2;p=2;q=3;forprime(r=5,1e9,if(p+w+ww,w=t;print1(", "q));p=q;q=r) \\ Charles R Greathouse IV, Jan 16 2012

Extensions

More terms from James Sellers, Dec 23 1999 and from Jud McCranie, Jun 16 2000
Showing 1-10 of 20 results. Next