login
a(n) is the least perfect square average of two consecutive primes with 2*n gap between them, or -1 if no such number exists.
0

%I #13 Feb 20 2023 12:27:37

%S 4,9,64,-1,144,625,324,2601,-1,154449,260100,1681,898704,27225,114244,

%T -1,278784,223729,4410000,25281,12888100,4730625,1512900,4774225,-1,

%U 8208225,6130576,1121481,12744900,34586161,2433600,45360225,9784384,1271279025,64064016,-1,69956496

%N a(n) is the least perfect square average of two consecutive primes with 2*n gap between them, or -1 if no such number exists.

%C 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).

%e 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.

%t 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 *)

%o (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

%Y Cf. A000040, A024675, A000290.

%K sign

%O 1,1

%A _Tamas Sandor Nagy_, Feb 19 2023

%E More terms from _Amiram Eldar_, Feb 19 2023