(i) Prove the following: A prime $p$ satisfying $p \equiv 1 \pmod 4$ can be written uniquely as the sum of two squares.
(ii) Prove Theorem (8.4).
(i) We know from Theorem (8.3) that a prime $p$ satisfying $p \equiv 1 \pmod 4$ can be written as the sum of two squares.
For the purpose of contradiction, let's assume $p$ can be written as a sum of two squares in two different ways.
$$ p = a^2 + b^2 = c^2 + d^2 $$
where $a, b, c, d$ are distinct, and all greater than 0, otherwise $p$ would not be prime.
The Conversion Identity (8.1), and question 12, gives us
$$ p^2 = (a^2 + b^2) (c^2 + d^2) = (ac− bd)^2 + (ad + bc)^2 = (ac+bd)^2 + (ad - bc)^2 $$
Now $p - a^2 = b^2$ and $p-c^2=d^2$, and so
$$ (p-a^2)d^2 = b^2d^2 = (p-c^2)b^2 $$
which gives us
$$ p(d^2-b^2) = a^2d^2 -b^2c^2 = (ad-bc)(ad+bc) \tag{i}$$
This means
$$ p \mid (ad-bc) \quad \lor \quad p \mid (ad+bc) $$
and so
$$ p^2 \mid (ad-bc)^2 \quad \lor \quad p^2 \mid (ad+bc)^2 $$
or for some integers $m,n$
$$ p^2m = (ad-bc)^2 \quad \lor \quad p^2 n = (ad+bc)^2 $$
Let's consider each case in turn.
Case $ p^2m = (ad-bc)^2$
From the conversion identities,
$$ p^2(1-m) = (ac+bd)^2 $$
Because $a,b,c,d$ are all greater than 0, this means $m=0$. And so $(ad-bc)^2=0$, that is, $ad-bc = 0$. Using this in (i) gives us $d^2-b^2 = 0$, that is $d=b$. Using $a^2+b^2 = c^2 + d^2$ with $d=b$ gives $a=c$. So we have
$$ a=c, \quad b=d $$
Case $ p^2 n = (ad+bc)^2$
From the conversion identitues,
$$ p^2(1-n) = (ac− bd)^2 $$
Here $n$ could be 1 or 0. But $n\ne0$, because that would mean $p^2 = (ac− bd)^2$ and from the conversion identities, that would mean $(ad + bc)^2=0$, a contradiction. And so $n=1$, which means $(ac-bd)^2=0$, that is $ac-bd=0$.
From $p-a^2=b^2$ and $p-d^2=c^2$, we have $(p-a^2)c^2=b^2c^2=(p-d^2)b^2$, which gives us
$$ p(c^2-b^2) = a^2c^2 - d^2b^2 = (ac-bd)(ac+bd) $$
Using $ac-bd=0$ with this gives $c^2-b^2=0$, that is $c=b$, which also gives us $a=d$. So we have
$$ a=d \quad b=c $$
Both cases lead to non-distinct sum of squares, and so we have shown that a prime $p$ satisfying $p \equiv 1 \pmod 4$ can be written uniquely as the sum of two squares.
(ii) Let's remind ourselves of Theorem (8.4):
An odd prime $p$ can be written as sum of two squares uniquely if and only if $p \equiv 1 \pmod 4$.
We have proved one direction in part (i) above. We only need to show that if a prime can be written uniquely as a sum of two squares then $p \equiv 1 \pmod 4$.
Let's write $p=a^2+b^2$ for some positive integers $a,b$. We know from Exercise (1.2).2 that the square of an integer is congruent to 0 or 1 modulo 4.
This means $p$ is congruent to 0, 1 or 2 modulo 4. But since $p$ is an odd prime, then $p$ cannot be congruent to 0 or 2 modulo 4, leaving only
$$ p \equiv 1 \pmod 4 $$
This concludes the proof.