# Every number is the sum of three squares with signs [duplicate]

This question already has an answer here:

The question. Can every $n\in \mathbb N$ can be written:

$$n=a^2\pm b^2\pm c^2$$

where $\pm$ are signs of your choice?

We know with Lagrange's four-square theorem that every integer can be written as the sum of four squares.

Plus, with have Legendre's three-square theorem stated that an integer can not be written as the sum of three squares if, and only if, it is of the form:

$$4^k(8n+7).$$

So we just have to prove (or disprove) it for every number of this form.

I have checked it until $55$, and it seems to work so far. So the number we have to check are these ones.

For instance:

$$31=6^2-2^2-1^2$$

and

$$39=6^2+2^2-1^2.$$

The issue here is that $a$, $b$ and $c$ can be arbitrarily large. For instance:

$$183=14542^2-14541^2-170^2.$$

So I don't really know how to prove or disprove this result, and I think it could go either way.

## marked as duplicate by Dietrich Burde, user91500, Claude Leibovici, Rohan, TastyRomeoFeb 15 '17 at 14:25

Hang on, it's actually quite simple!

So suppose that we have a number $$l$$. Suppose that $$l=pq$$, with $$p,q$$ having the same parity. That is, both $$p$$ and $$q$$ are even, or both $$p$$ and $$q$$ are odd.

If this is the case, consider $$a= \frac{p+q}{2}, b= \frac{p-q}{2}$$. Then, note that $$a^2 - b^2 = pq = l$$!

For example, $$183 = 61 \times 3$$, so $$a=32$$ and $$b = 29$$, and $$32^2-29^2 = 1024 - 841 = 183$$.

Now, when can $$l$$ be written in this form? At least when $$l$$ is odd, because then you can split it into two odd factors (even if one of those factors is $$1$$ : for example $$7=7 \times 1 = 4^2-3^2$$) and carry out the above procedure.

Finally, given an even number, just subtract (or add!) $$1^2=1$$ to make it an odd number,which can be expressed as a difference of squares.

For example: given $$39$$, we can write $$39=13 \times 3 = 8^2 - 5^2$$. Given $$78$$, we can write $$78 = 77 + 1 = 11 \times 7 +1 = 9^2-2^2+1^2$$.

What is the reason for so much flexibility? Simple : $$(a^2-b^2)$$ has a non-trivial factorization, while $$a^2+b^2$$ does not. This is what makes the whole additive theory of squares (and the Waring problem) so interesting and difficult.

$2n+1=(n+1)^2-n^2+0^2$ and $2n=(n+1)^2-n^2-1^2$ cover the odd and even cases respectively.

• Or, to avoid use of zeroes, $2n+1=(n+3)^2-(n+2)^2-2^2$. – Adam Bailey Feb 15 '17 at 11:32

Hint: show that every $n$ which is not of the form $4k+2$ can be written in the form $a^2-b^2+0^2$ for some $a$ and $b$. Then $4k+2$ can be written in the form $a^2-b^2-1^2$ for some $a$ and $b$.

(Thanks to John Bentin for pointing out the silly error in my original post.)

• Thanks, I made a mistake. It is actually anything not 2 mod 4, will edit. – Especially Lime Feb 15 '17 at 9:42
• @JohnBentin I do not see the connection either... I want to say odd number since $(n+1)^2-n^2=2n+1$ which is odd. – E. Joseph Feb 15 '17 at 9:42
• @E.Joseph you can also get all multiples of $4$ from $(n+1)^2-(n-1)^2$. – Especially Lime Feb 15 '17 at 9:47