OFFSET
0,2
LINKS
Charles R Greathouse IV and Giovanni Resta, Table of n, a(n) for n = 0..211 (terms < 10^14, first 156 terms from Charles R Greathouse IV)
EXAMPLE
23 is 4 units away from the closest prime (not including itself), so 23 is in the sequence.
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 *)
PROG
(PARI) print1(0); w=2; p=2; q=3; forprime(r=5, 1e9, if(p+w+w<q, for(t=p+w+1, (q+p)\2, print1(", "t)); w=(q-p)\2); t=min(q-p, r-q); if(t>w, w=t; print1(", "q)); p=q; q=r) \\ Charles R Greathouse IV, Jan 16 2012
CROSSREFS
KEYWORD
nonn,nice
AUTHOR
EXTENSIONS
More terms from James A. Sellers, Dec 23 1999 and from Jud McCranie, Jun 16 2000
STATUS
approved