login
Numbers of the form p^2 + q^2 + r^2, where p, q, and r are primes.
3

%I #10 Dec 17 2021 11:07:14

%S 12,17,22,27,33,38,43,54,57,59,62,67,75,78,83,99,102,107,123,129,134,

%T 139,147,150,155,171,174,177,179,182,187,195,198,203,219,222,227,243,

%U 246,251,267,291,294,297,299,302,307,315,318,323,339,342,347,363,369

%N Numbers of the form p^2 + q^2 + r^2, where p, q, and r are primes.

%H T. D. Noe, <a href="/A214514/b214514.txt">Table of n, a(n) for n = 1..10000</a>

%t nn = 10^3; ps = Prime[Range[PrimePi[Sqrt[nn]]]]; t = Flatten[Table[ps[[i]]^2 + ps[[j]]^2 + ps[[k]]^2, {i, Length[ps]}, {j, i, Length[ps]}, {k, j, Length[ps]}]]; t = Select[t, # <= nn &]; Union[t]

%o (Python)

%o from sympy import primerange as primes

%o from itertools import takewhile, combinations_with_replacement as mc

%o def aupto(N):

%o psqs = list(takewhile(lambda x: x<=N, (p**2 for p in primes(1, N+1))))

%o sum3 = set(sum(c) for c in mc(psqs, 3) if sum(c) <= N)

%o return sorted(sum3)

%o print(aupto(369)) # _Michael S. Branicky_, Dec 17 2021

%Y Cf. A045636 (two primes), A214515 (four primes).

%K nonn

%O 1,1

%A _T. D. Noe_, Jul 29 2012