%I #13 Jan 06 2023 10:42:19
%S 3,7,7,1627,83,7,23,7,19,17,73,281,179,257,5,43,73,43,19,67,911,193,7,
%T 1613,139,383,7,719,113,967,31,19,211,769,149,173,13,13,59,137,23,47,
%U 89,607,61,127,61,317,1049,1277,547,281,317,4157,199,107,373,149,229,367,1489,643,563,587,263
%N a(n) is the first prime p such that the average of the squares of n consecutive primes starting with p is prime.
%C Suggested in an email by _J. M. Bergot_.
%H Robert Israel, <a href="/A359322/b359322.txt">Table of n, a(n) for n = 2..10000</a>
%e a(3) = 7 because 7, 11, 13 are 3 consecutive primes and (7^2 + 11^2 + 13^2)/3 = 113 is prime, and 7 is the least prime that works.
%p f:= proc(n) local P,s,i;
%p P:= <seq(ithprime(i),i=1..n)>;
%p s:= add(P[i]^2,i=1..n)/n;
%p do
%p if s::integer and isprime(s) then return P[1] fi;
%p s:= s - P[1]^2/n;
%p P[1..-2] := P[2..-1]; P[n]:= nextprime(P[n]);
%p s:= s + P[n]^2/n;
%p od
%p end proc:
%p map(f, [$2..70]);
%o (Python)
%o from sympy import prime, isprime, nextprime, primerange
%o def a(n):
%o plst = list(primerange(2, prime(n)+1))
%o powsum = sum(p**2 for p in plst)
%o while True:
%o q, r = divmod(powsum, n)
%o if r == 0 and isprime(q): return plst[0]
%o powsum -= plst[0]**2
%o plst = plst[1:] + [nextprime(plst[-1])]
%o powsum += plst[-1]**2
%o print([a(n) for n in range(2, 67)]) # _Michael S. Branicky_, Dec 29 2022
%K nonn
%O 2,1
%A _Robert Israel_, Dec 25 2022
|