Square equal to sum of three squares

You are correct: If $p > 2$ is prime, then $p^2$ can always be written as the sum of three squares at least two of which are non-zero.

Let $s(n)$ denote the number of ways of writing $n = a^2 + b^2 + c^2$, where $a$, $b$, and $c$ are integers (positive or negative) and not accounting for symmetries. One has $s(1) = 6$.

If $p > 2$ is prime, then $p^2$ can be written as a sum of three squares (including degenerate examples) in

$$6\left(p + 1 - \left( \frac{-1}{p} \right)\right)$$

ways. (For a reference, see https://mathoverflow.net/questions/3596/is-there-a-simple-way-to-compute-the-number-of-ways-to-write-a-positive-integer). For example, if $p = 3$, then $(-1/3) = -1$ so we get $30$ ways, and indeed

$$3^2 = (\pm 3)^2 + 0^2 + 0^2 = 0^2 + (\pm 3)^2 + 0^2 = 0^2 + 0^2 + (\pm 3)^2,$$

giving $3 \times 2 = 6$ ways, and

$$3^2 = (\pm 2)^2 + (\pm 2)^2 + (\pm 1)^2 = (\pm 2)^2 + (\pm 1)^2 + (\pm 2)^2 = (\pm 1)^2 + (\pm 2)^2 + (\pm 2)^2$$

giving $3 \times 8 = 24$ ways. The examples you wish to rule out at the ones where either $a$, $b$, or $c$ is $\pm p$, and this gives $6$ solutions. Hence you simply need to observe that $p + 1 - (-1/p) > 1$, which is always true.


Some Pythagorean triples:

$3^2+4^2=5^2$

$5^2+12^2=13^2$

So: $3^2+4^2+12^2=13^2$

Generalize that:

$(3t)^2+(4t)^2+(12t)^2=(13t)^2$

$n=13t$ , $t> 0 $


If we want $a^2+b^2+c^2=n^2$, then $a^2+b^2=n^2-c^2=(n-c)(n+c)$.

So a way to generate solutions is to choose $a$ and $b$ and then try to find $n$ and $c$ that work.

Example: $a=10$, $b=11$. So $a^2+b^2=100+121=221$.

Now $221=13*17=(15-2)(15+2)$. So a solution should be $10^2+11^2+2^2=15^2$.

You could also write $221=221=1*221=(111-110)(111+110)=111^2-110^2$. So another solution would be $10^2+11^2+110^2=111^2$.

I will leave it to you to explore this idea further if you wish.