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 #41 Feb 13 2024 06:57:24
%S 0,23,53,120,211,1340,1341,1342,1343,1344,2179,3967,15704,15705,16033,
%T 19634,19635,24281,31428,31429,31430,31431,31432,31433,38501,58831,
%U 155964,203713,206699,370310,370311,370312,370313,370314,370315,370316
%N Lonely numbers: distance to closest prime sets a new record.
%H Charles R Greathouse IV and Giovanni Resta, <a href="/A051650/b051650.txt">Table of n, a(n) for n = 0..211</a> (terms < 10^14, first 156 terms from Charles R Greathouse IV)
%e 23 is 4 units away from the closest prime (not including itself), so 23 is in the sequence.
%t 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 *)
%t 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 *)
%o (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
%Y Related sequences: A023186-A023188, A046929-A046931, A051650, A051652, A051697-A051702, A051728-A051730.
%Y Distances are in A051730.
%K nonn,nice
%O 0,2
%A _N. J. A. Sloane_
%E More terms from _James A. Sellers_, Dec 23 1999 and from _Jud McCranie_, Jun 16 2000