OFFSET
1,1
COMMENTS
For n > 1, no prime gap that is twice a square can have a perfect square in its middle as the average of the two consecutive primes with that gap between them. It is because then the lesser of the candidate consecutive primes could be factored into a composite of two integers greater than 1, by the algebraic identity a^2 - b^2 = (a - b)*(a + b).
EXAMPLE
a(3) = 64 is a term because 64 = 8^2, a perfect square, which is the least such number that is the average of two consecutive primes 61 and 67, with 2*3 = 6 being the prime gap between them.
MATHEMATICA
seq[len_, pmax_] := Module[{s = Table[0, {len}], p = 3, c = 0, q, m, d}, Do[s[[i^2]] = -1; c++, {i, 2, Floor[Sqrt[len]]}]; While[c < len && p < pmax, q = NextPrime[p]; d = (q - p)/2; m = (p + q)/2; If[d <= len && s[[d]] == 0 && IntegerQ[Sqrt[m]], c++; s[[d]] = m]; p = q]; s]; seq[20, 10^7] (* Amiram Eldar, Feb 19 2023 *)
PROG
(PARI) a(n) = if ((n>1) && issquare(n), return(-1)); forprime(p=2, oo, my(q=nextprime(p+1), s); if ((q-p == 2*n) && issquare(s=(p+q)/2), return(s))); \\ Michel Marcus, Feb 20 2023
CROSSREFS
KEYWORD
sign
AUTHOR
Tamas Sandor Nagy, Feb 19 2023
EXTENSIONS
More terms from Amiram Eldar, Feb 19 2023
STATUS
approved