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

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

A163492 Numbers such that the two adjacent integers are a perfect square and a prime.

Original entry on oeis.org

1, 2, 3, 8, 10, 24, 48, 80, 82, 168, 224, 226, 360, 440, 442, 728, 840, 1088, 1090, 1224, 1368, 1522, 1848, 2026, 2208, 2400, 3024, 3250, 3720, 3968, 4760, 5040, 5624, 5928, 6562, 7920, 8648, 9802, 10608, 11026, 11448, 12322, 13688, 13690, 14160, 14640
Offset: 1

Views

Author

Gaurav Kumar, Jul 29 2009

Keywords

Comments

Also known as the Beprisque numbers.

Examples

			a(1) = 2 since 2 lies between 1(square) and 3(prime).
a(2) = 3 since 3 lies between 2(prime) and 4(square).
		

Crossrefs

Programs

  • Mathematica
    nn = 100; Sort[Select[Range[0, nn], PrimeQ[#^2 + 2] &]^2 + 1, Select[Range[nn], PrimeQ[#^2 - 2] &]^2 - 1] (* T. D. Noe, Aug 29 2012 *)
    Select[Range[15000],AnyTrue[#+{1,-1},PrimeQ]&&AnyTrue[{Sqrt[#-1],Sqrt[ #+1]},IntegerQ]&] (* Harvey P. Dale, Feb 06 2023 *)

Extensions

Definition clarified by R. J. Mathar, Aug 08 2009
Number 1 added by WG Zeist, Aug 28 2012

A051701 Closest prime to n-th prime p that is different from p (break ties by taking the smaller prime).

Original entry on oeis.org

3, 2, 3, 5, 13, 11, 19, 17, 19, 31, 29, 41, 43, 41, 43, 47, 61, 59, 71, 73, 71, 83, 79, 83, 101, 103, 101, 109, 107, 109, 131, 127, 139, 137, 151, 149, 151, 167, 163, 167, 181, 179, 193, 191, 199, 197, 199, 227, 229, 227, 229, 241, 239, 257, 251, 257, 271, 269
Offset: 1

Views

Author

Keywords

Comments

A227878 gives the terms occurring twice. - Reinhard Zumkeller, Oct 25 2013

Examples

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

Crossrefs

Programs

  • Haskell
    a051701 n = a051701_list !! (n-1)
    a051701_list = f 2 $ 1 : a000040_list where
       f d (q:ps@(p:p':_)) = (if d <= d' then q else p') : f d' ps
         where d' = p' - p
    -- Reinhard Zumkeller, Oct 25 2013
    
  • Mathematica
    a[n_] := (p = Prime[n]; np = NextPrime[p]; pp = NextPrime[p, -1]; If[np-p < p-pp, np, pp]); Table[a[n], {n, 1, 58}] (* Jean-François Alcover, Oct 20 2011 *)
    cp[{a_,b_,c_}]:=If[c-bHarvey P. Dale, Oct 08 2012 *)
  • Python
    from sympy import nextprime
    def aupton(terms):
      prv, cur, nxt, alst = 0, 2, 3, []
      while len(alst) < terms:
        alst.append(prv if 2*cur - prv <= nxt else nxt)
        prv, cur, nxt = cur, nxt, nextprime(nxt)
      return alst
    print(aupton(58)) # Michael S. Branicky, Jun 04 2021

Extensions

More terms from James Sellers

A060272 Distance from n^2 to closest prime.

Original entry on oeis.org

1, 1, 2, 1, 2, 1, 2, 3, 2, 1, 6, 5, 2, 1, 2, 1, 4, 7, 2, 1, 2, 3, 6, 1, 6, 1, 2, 3, 2, 7, 6, 3, 2, 3, 2, 1, 2, 3, 2, 1, 12, 5, 2, 3, 2, 3, 2, 5, 2, 3, 8, 3, 6, 1, 2, 1, 2, 3, 10, 7, 2, 3, 2, 3, 4, 1, 4, 3, 2, 3, 2, 5, 4, 1, 2, 3, 2, 5, 6, 3, 2, 5, 6, 1, 4, 3, 4, 3, 2, 1, 6, 3, 2, 1, 4, 5, 4, 3, 2, 7, 8, 5, 2
Offset: 1

Views

Author

Labos Elemer, Mar 23 2001

Keywords

Examples

			n=1: n^2=1 has next prime 2, so a(1)=1;
n=11: n^2=121 is between primes {113,127} and closer to 127, thus a(11)=6.
		

Crossrefs

Programs

  • Maple
    seq((s-> min(nextprime(s)-s, `if`(s>2, s-prevprime(s), [][])))(n^2), n=1..256);  # edited by Alois P. Heinz, Jul 16 2017
  • Mathematica
    Table[Function[k, Min[k - #, NextPrime@ # - k] &@ If[n == 1, 0, Prime@ PrimePi@ k]][n^2], {n, 103}] (* Michael De Vlieger, Jul 15 2017 *)
    Min[#-NextPrime[#,-1],NextPrime[#]-#]&/@(Range[110]^2) (* Harvey P. Dale, Jun 26 2021 *)
  • PARI
    a(n) = if (n==1, nextprime(n^2) - n^2, min(n^2 - precprime(n^2), nextprime(n^2) - n^2)); \\ Michel Marcus, Jul 16 2017

Formula

a(n) = abs(A000290(n) - A113425(n)) = abs(A000290(n) - A113426(n)). - Reinhard Zumkeller, Oct 31 2005

A132860 Smallest number at distance 2n from nearest prime (variant 2).

Original entry on oeis.org

2, 0, 93, 119, 531, 897, 1339, 1341, 1343, 9569, 15703, 15705, 19633, 19635, 31425, 31427, 31429, 31431, 31433, 155959, 155961, 155963, 360697, 360699, 360701, 370311, 370313, 370315, 370317, 1349591, 1357261, 1357263, 1357265, 1357267
Offset: 1

Views

Author

R. J. Mathar, Nov 18 2007, Nov 30 2007

Keywords

Comments

Let f(m) be the distance to the nearest prime as defined in A051699(m). Then a(n) = min { m: f(m)= 2n }. A051728 uses A051700(m) to define the distance.
Note that the requirement f(m)>=2n yields the same sequence as f(m)=2n here. (Reasoning: We are essentially probing for prime gaps of size 4n or larger while increasing m. One cannot get earlier hits by relaxing the requirement from the equal to the larger-or-equal sign, because m triggers as soon as the distance to the start of the gap reaches 2n, with both definitions. This is an inherent consequence of using A051699.)

Crossrefs

Programs

  • Maple
    A051699 := proc(m) if isprime(m) then 0 ; elif m <= 2 then op(m+1,[2,1]) ; else min(nextprime(m)-m,m-prevprime(m)) ; fi ; end: a := proc(n) local m ; for m from 0 do if A051699(m) = 2 * n then RETURN(m) ; fi ; od: end: seq(a(n),n=0..18);

Formula

a(n) = min {m : A051699(m) = 2n}.

A132861 Smallest number at distance 3n from nearest prime (variant 2).

Original entry on oeis.org

2, 26, 53, 532, 211, 1342, 2179, 15704, 16033, 31424, 24281, 31430, 31433, 155960, 58831, 360698, 206699, 370312, 370315, 492170, 1357261, 1357264, 1357267, 2010802, 2010805, 4652428, 12485141, 17051788, 17051791, 17051794, 11117213, 20831416, 10938023, 20831422
Offset: 0

Views

Author

R. J. Mathar, Nov 18 2007

Keywords

Comments

Let f(m) be the distance to the nearest prime as defined in A051700(m). Then a(n) = min {m: f(m) = 3n} for n > 0. A132470 uses A051699(m) to define the distance. a(n) <= A132470(n) because here primes at the start or end of a prime gap of size 3n may be picked, which would be discarded in A132470 for n>0; this gives a chance to minimize m here further than in A132470.

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: a := proc(n) local m ; if n = 0 then RETURN(2); else for m from 0 do if A051700(m) = 3 * n then RETURN(m) ; fi ; od: fi ; end: seq(a(n),n=0..18);
  • 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) != 3*n: m += 1
      return m
    print([a(n) for n in range(13)]) # Michael S. Branicky, Feb 26 2021

Formula

a(n) = min {m : A051700(m) = 3n} for n > 0.
a(n) = A051652(3*n). [From R. J. Mathar, Jul 22 2009]

Extensions

7 more terms from R. J. Mathar, Jul 22 2009
4 more terms from R. J. Mathar, Aug 21 2018
a(30) and beyond and edits from Michael S. Branicky, Feb 26 2021

A163768 Distance of Fibonacci(n) to the closest prime which is not Fibonacci(n) itself.

Original entry on oeis.org

2, 1, 1, 1, 1, 2, 1, 2, 2, 3, 2, 6, 5, 4, 2, 3, 4, 4, 5, 4, 2, 3, 2, 4, 13, 4, 10, 11, 14, 10, 23, 4, 4, 9, 10, 14, 11, 6, 12, 3, 2, 6, 7, 12, 16, 9, 24, 6, 5, 20, 18, 23, 14, 6, 9, 12, 10, 21, 4, 30, 13, 38, 4, 7, 16, 12, 19, 36, 22, 31, 4, 32, 11, 12, 60, 7, 2, 6, 27, 12, 62, 25, 20, 6, 19, 78
Offset: 0

Views

Author

Jonathan Vos Post, Aug 04 2009

Keywords

Comments

The closest prime to F(n) -- next closest if F(n) itself is prime -- for n = 0, 1, 2, 3, 4, ...:
2, 2, 2, 3, 2, 3 or 7, 7, 11, 19 or 23, 31 or 37, 53, 83, 139 or 149, 229, 379, 607 or 613.

Examples

			a(0) = 2 because 2 is the closest prime to F(0) = 0, and 2-0 = 2.
a(1) = 1 because 2 is the closest prime to F(1) = 1, and 2-1 = 1.
a(3) = 1 because 3 is the closest prime to F(3) = 2 other than the prime F(3) = 2 itself, and 3-2 = 1.
		

Crossrefs

Programs

  • Maple
    A051700 := proc(n) if n < 2 then 2-n; elif n = 2 then 1 ; else min( nextprime(n)-n, n-prevprime(n) ); fi; end:
    A000045 := proc(n) combinat[fibonacci](n) ; end:
    A163768 := proc(n) A051700(A000045(n)) ; end: seq(A163768(n), n=0..100) ; # R. J. Mathar, Aug 06 2009
  • Mathematica
    g[n_]:=Module[{fn=Fibonacci[n],a,b},a=NextPrime[fn,-1];b=NextPrime[fn];Min[Abs[fn-a],Abs[b-fn]]]; Table[g[i],{i,0,100}] (* Harvey P. Dale, Jan 15 2011 *)

Formula

For n not in A001605: a(n) = MIN{|A000045(n) - A000040(i)} = A079677(n).
For n in A001605: a(n) = MIN{k such that k > 0 and |A000045(n) - A000040(i)| = k}.
a(n) = A051700(A000045(n)). - R. J. Mathar, Aug 06 2009

Extensions

More terms from R. J. Mathar, Aug 06 2009, reformatted Aug 29 2009

A308261 For any integer n, let d(n) be the smallest k > 0 such that at least one of n-k or n+k is a prime number; we build an undirected graph G on top of the prime numbers as follows: two consecutive prime numbers p and q are connected iff at least one of d(p) or d(q) equals q-p; a(n) is the number of terms in the n-th connected component of G (ordered by least element).

Original entry on oeis.org

4, 2, 3, 2, 7, 3, 3, 3, 3, 2, 2, 8, 2, 7, 2, 5, 4, 4, 2, 4, 5, 3, 2, 2, 3, 4, 3, 3, 2, 2, 5, 8, 7, 4, 2, 5, 3, 2, 2, 2, 2, 3, 4, 4, 3, 5, 4, 2, 2, 2, 3, 2, 3, 6, 3, 2, 2, 4, 6, 2, 3, 2, 4, 3, 4, 2, 5, 4, 3, 7, 4, 2, 2, 2, 3, 4, 4, 4, 2, 5, 4, 2, 2, 5, 3, 3, 2
Offset: 1

Views

Author

Rémy Sigrist, Jun 02 2019

Keywords

Comments

Each connected component of G has at least two elements.
Is the sequence bounded?

Examples

			The first terms, alongside the corresponding components, are:
  n  a(n)   n-th component
  -- ----   --------------
   1    4   {2, 3, 5, 7}
   2    2   {11, 13}
   3    3   {17, 19, 23}
   4    2   {29, 31}
   5    7   {37, 41, 43, 47, 53, 59, 61}
   6    3   {67, 71, 73}
   7    3   {79, 83, 89}
   8    3   {97, 101, 103}
   9    3   {107, 109, 113}
  10    2   {127, 131}
		

Crossrefs

Programs

  • PARI
    d(p) = for (k=1, oo, if (p-k>0 && isprime(p-k), return (k), isprime(p+k), return (k)))
    v=1; p=2; forprime (q=p+1, oo, if (d(p)==q-p || d(q)==q-p, v++, print1 (v", "); if (n++==87, break); v = 1); p=q)

A133490 Smallest number at distance 2n from nearest prime (variant 3).

Original entry on oeis.org

2, 0, 23, 53, 211, 211, 211, 1341, 1343, 2179, 3967, 15705, 16033, 19635, 24281, 24281, 31429, 31431, 31433, 38501, 38501, 58831, 203713, 206699, 206699, 370311, 370313, 370315, 370317, 1272749, 1272749, 1272749, 1357265, 1357267, 2010801
Offset: 0

Views

Author

R. J. Mathar, Nov 30 2007

Keywords

Comments

Let f(m) be the distance to the nearest prime as defined in A051700(m). Then a(n) = min { m: f(m)>= 2n}. The variants of a different definition of "distance" or demanding equality, f(m)=2n, are in A132860 and A051728.
Showing 1-10 of 12 results. Next