OFFSET
1,1
LINKS
Hugo Pfoertner, Table of n, a(n) for n = 1..55, terms 1..50 from Ken Takusagawa.
EXAMPLE
a(1) = 2 as 2 has only one prime neighbor, 3 and 3-2 = 1, the first possible record. a(2) = 3 because the sum of the distances (gaps) from 3 to its two neighboring primes is 3-2 + 5-3 = 3 > 1, beating the previous record. a(5) = 23 because 23, with 29-19 = 10, is the smallest prime beating a(4) = 7's 11-5 = 6.
MATHEMATICA
PrimeNextDelta[n_]:=(Do[If[PrimeQ[n+k], a=n+k; d=a-n; Break[]], {k, 9!}]; d); PrimePrevDelta[n_]:=(Do[If[PrimeQ[n-k], a=n-k; d=n-a; Break[]], {k, n}]; d); q=0; lst={2}; Do[p=Prime[n]; d1=PrimeNextDelta[p]; d2=PrimePrevDelta[p]; d=d1+d2; If[d>q, AppendTo[lst, p]; q=d], {n, 2, 10^4}]; lst (* Vladimir Joseph Stephan Orlovsky, Aug 07 2008 *)
Join[{2}, DeleteDuplicates[{#[[2]], #[[3]]-#[[1]]}&/@Partition[Prime[Range[6 10^6]], 3, 1], GreaterEqual[#1[[2]], #2[[2]]]&][[All, 1]]] (* Harvey P. Dale, Jul 05 2022 *)
PROG
(PARI) /* 436272953 is the next-to-the-largest precalculated prime */
/* with which PARI/GP (Version 2.0.17 (beta) at least) can be started */
/* A different program would be required to go beyond a(37)=325737821 */
{r=0; print1("2, "); forprime(p=3, 436272953,
s=nextprime(p+1)-precprime(p-1); if(s>r, print1(p, ", "); r=s))}
CROSSREFS
KEYWORD
nonn
AUTHOR
Rick L. Shepherd, Jun 21 2004
STATUS
approved