# Perfect square as sum of two perfect squares

I refer to this question.

Given a perfect square, can you prove that it is a sum of two perfect squares?

I recently saw this:

Let $p,q$ be primes. $p_i \equiv 1 \pmod 4$ and $q_i \equiv 3 \pmod 4$.

$N=p_1^{a_1}p_2^{a_2}\cdots q_1^{b_1}q_2^{b_2}\cdots$

$N$ can be written as sum of 2 squares iff all $b$ are even.

I used an identity that can multiply two numbers that can be written as sum of two perfect squares into a number that can be written as two perfect squares. And I have proved that the $p$ part can be written as two squares. Hence it is left to prove that the $q$ part can be written as sum of two squares.

Any help is appreciated. Thanks.

• How would you write $9$ as the sum of two squares – Will Jagy Mar 21 '18 at 2:27
• A good book - Proofs from THE BOOK by Aigner, Martin, Ziegler, Günter M. (P.17) – CY Aries Mar 21 '18 at 2:29
• In case you allow $0^2$, then $a^2=a^2+0^2$. Otherwise, $9=3^2$ is a counterexample. – Prasun Biswas Mar 21 '18 at 2:31
• @PrasunBiswas Oh thank you! I didn't think of 0... Should I delete the question or what? – Vee Hua Zhi Mar 21 '18 at 2:54
• $0$ should be allowed. – CY Aries Mar 21 '18 at 2:56

This is the outline of the proof found in the book "Proofs from THE BOOK" (P.17-22) by Aigner, Martin, Ziegler, Günter M. It is too long to put in a comment so I put it here. Please do not vote for it.

Lemma 1. For primes $p=4m+1$ the equation $s^2\equiv -1$ (mod $p$) has two solutions $s\in\{1,2,\dots,p-1\}$, for $p=2$ there is one such solution, while for primes of the form $4m+3$ there is no solution

Lemma 2. No number $n=4m+3$ is a sum of two squares.

Proposition. Every prime of the form $p=4m+1$ is a sum of two squares, that is, it can be written as $p=x^2+y^2$ for some natural numbers $x,y\in\mathbb{N}$

Theorem. A natural number $n$ can be represented as a sum of two squares if and only if every prime factor of the form $p=4m+3$ appears with an even exponent in the prime decomposition of $n$.

• Rather than asking others not to vote your answer, you can make this answer a community wiki if you don't want the free rep. – Prasun Biswas Mar 23 '18 at 10:22

The proof is not very hard when using the decomposition of prime numbers in the Gaussian ring $\mathbf Z [i]$ : $2$ is ramified, the odd primes $p\equiv -1$ mod $4$ remain prime ("inert"), and the primes $p\equiv 1$ mod $4$ are "decomposed" as $p=u\pi \bar \pi$, where $u=\pm 1, \pm i$ and $\pi , \bar \pi$ are two conjugate primes of $\mathbf Z [i]$ . Taking norms immediately yields Fermat's classical theorem that $2$ and the $p\equiv 1$ mod $4$ are sums of two squares. It follows readily that an integer $m=\prod {p_i} ^{a_i}$ is a sum of two squares iff $a_i$ is even whenever $p_i \equiv -1$ mod $4$ : just decompose $m$ in $\mathbf Z [i]$ (which is a principal domain) and take the norm map (which is multiplicative).