Number theory counting sums of squares modulus This is an extra question from an old examination paper: 

VI. Let $n>1$ in $\mathbf{Z}$ and let $r(n) = \#\{(a,b)\in \mathbf{Z}^{2};n=a^{2}+b^{2}\}$ Let also $n=n'n''n'''$ where $n',n'',n''' \in \mathbf{N}$ and 
$p|n' \Longrightarrow p\equiv 1\mod 4 ; p|n'' \Longrightarrow p=2 ; p|n''' \Longrightarrow p\equiv 3 \mod 4$ 
for $p\in \mathbf{N}$ prime. 
i) Show that if $n'''$ is not a square, then $r(n)=0$.
ii) Show that if $n'''$ is a square and $n' = 1$, then $r(n)=4$
iii) Show that if $n'''$ is a square and $1<n'=p_{1}^{e_{1}}\ddots p_{k}^{e_{k}}$ where $p_{1},...,p_{k}$ are different primes in $\mathbf{N}$ and $e_{1},...,e_{k} \in \mathbf{N}$, then it holds that $r(n)=r(n')=4(e_{1}+1)\ddots (e_{k}+1)$

I am completely dumbstruck and can't see how to begin (and neither did an older student who took this exam and whom I asked for hints). Help is greatly appreciated.  
 A: The above theorem can be summarized by defining $r_0(n)=\frac{r(n)}4$, and then showing:


*

*$r_0(n)$ is multiplicative - that is, if $m,n$ are relatively prime, then $r_0(nm)=r_0(n)r_0(m)$.

*If $p\equiv 3\pmod 4$ is prime, then $r_0(p^k)=0$ if $k$ odd, and $r_0(p^k)=1$ if $k$ even.

*$r_0(2^k)=1$ for all k

*$r_0(p^k)=k+1$ if $p\equiv 1\pmod 4$ is prime


(1) is shown using unique factorization in $\mathbb Z[i]$. (2) is essentially due to the fact that $-1$ is not a square mod $p$ if $p\equiv 3\pmod 4$.  (3) You can essentially brute force. (4) Again uses unique factorization in $\mathbb Z[i]$.
A: Outline:
Step 1: Prove Fermats Theorem which states that every prime $p\equiv 1 \pmod{4}$ can be written as the sum of two squares uniquely up to order and sign.  I would hope that this was already done in your class, since its proof will require by far the most work here.
Step 2: Show that $\frac{1}{4}r(n)$ is a multiplicative function.  This follows since $\mathbb{Z}[i]$ is a unique factorization domain, and that the norm is multiplicative.  
From here, you can conclude both $(ii)$ and $(iii)$. (i) then follows from considering modulo $4$.  (and using multiplicativity)
