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.

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