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