Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).
%I #26 Jul 25 2019 17:30:58
%S 2,4,6,7,12,13,14,15,16,17,18,20,21,22,24,25,26,30,31,32,33,34,35,36,
%T 40,42,43,44,48,49,50,51,52,53,54,55,56,57,62,63,64,65,66,67,68,69,70,
%U 71,72,73,74,75,76,77,96,98,99,100,101,102,103,104,105,106,107,108,109
%N Distance from A051650(n) to nearest prime.
%H Amiram Eldar, <a href="/A051730/b051730.txt">Table of n, a(n) for n = 0..211</a> (calculated from the b-file at A051650)
%e 23 is 4 units away from the closest prime (not including itself), so 4 is in the sequence.
%t (* 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 *)
%o (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
%o (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
%Y Related sequences: A023186-A023188, A046929-A046931, A051650, A051652, A051697-A051702, A051728-A051730.
%K nonn,easy,nice
%O 0,1
%A _N. J. A. Sloane_
%E More terms from _James A. Sellers_, Dec 23 1999 and from _Jud McCranie_, Jun 16 2000
%E Further terms from _Naohiro Nomoto_, Jun 21 2001