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 18 results. Next

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

A046931 Prime islands: for n >= 2, a(n) = least prime whose adjacent primes are exactly 2n apart; a(1) = 3 by convention.

Original entry on oeis.org

3, 5, 7, 29, 23, 53, 89, 223, 113, 331, 631, 211, 1381, 1129, 1637, 4759, 2579, 3433, 4297, 1327, 2179, 2503, 7993, 5623, 9587, 17257, 15859, 14107, 19609, 34981, 36433, 33247, 24281, 35617, 43331, 19661, 134513, 31397, 137029
Offset: 1

Views

Author

Keywords

Comments

For n > 1: (n) = A000040(A261525(n)+1) for n > 1. - Reinhard Zumkeller, Aug 23 2015

Examples

			29 is in a sea of 6 composites, namely 24, 25, 26, 27, 28 and 30 and is the smallest such number, so a(4) = 29.
		

Crossrefs

Another version: see A098968 and A098969.
Cf. A031131. - Zak Seidov, Jan 25 2015

Programs

  • Mathematica
    Join[{3},Transpose[Flatten[Table[Select[Partition[Prime[Range[ 20000]],3,1], Last[#]-First[#]==2 n&,1],{n,2,45}],1]][[2]]] (* Harvey P. Dale, May 22 2012 *)

Extensions

Typo in example fixed by Zak Seidov, Jan 25 2015

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

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

A051730 Distance from A051650(n) to nearest prime.

Original entry on oeis.org

2, 4, 6, 7, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 24, 25, 26, 30, 31, 32, 33, 34, 35, 36, 40, 42, 43, 44, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 96, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109
Offset: 0

Views

Author

Keywords

Examples

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

Crossrefs

Programs

  • Mathematica
    (* b stands for A051650 *) d[0] = 2; d[k_] := Min[k - NextPrime[k, -1], NextPrime[k] - k]; b[0] = 0; b[n_] := b[n] = (k = b[n-1] + 1; record = d[b[n-1]]; While[d[k] <= record, k++]; k); a[n_] := a[n] = d[b[n]]; Table[ Print[ a[n]]; a[n], {n, 0, 66}] (* Jean-François Alcover, Jan 16 2012 *)
  • PARI
    print1(w=2);p=2;q=3;forprime(r=5,1e9,if(p+w+ww,w=t;print1(", "t));p=q;q=r) \\ Charles R Greathouse IV, Jan 16 2012
  • UBASIC
    [10] C#=pack(3,5):R=2:N=4:print 2; [20] if N>member(C#,2) then C#=pack(member( C#,2)):C#=C#+nxtprm(member(C#,1)) [30] Prv=member(C#,1):Nxt=member(C#,2) [40] if Nxt=N then Nxt=nxtprm(N) [50] if (N-Prv)>=(Nxt-N) then P=Nxt-N else P=N-Prv [60] if P>R then print P;:R=P [70] N+=1 :goto 20
    

Extensions

More terms from James Sellers, Dec 23 1999 and from Jud McCranie, Jun 16 2000
Further terms from Naohiro Nomoto, Jun 21 2001
Showing 1-10 of 18 results. Next