Recall the question, let
be a prime, in how many ways can we write
as a sum of two squares?
The answer is
, i.e. if
, then the pair
works. However, the following pairs also work: 
The reason is simple if one thinks in terms of Gaussian integers
Recall that the Gaussian primes are precisely the following:
1)
.
2) Rational primes
of the form 
3)
such that
, a rational prime.
Since
has unique factorization, if
, we must have
, therefore
must be a Gaussian prime, and hence the prime divisors of
are precisely
and its unit multiples, namely:
Likewise for the conjugate
, we also have
. Therefore, this gives 8 different ways to write
as a sum of two squares.
For the general question: For a given integer
, how many ways can we write it as a sum of two squares. For this, let
to denote the number of ways to write
as a sum of
squares. We have:

For the proof, one may try to use Gaussian integers. There is a more general method that deals with finding
, which uses the theory of modular forms. I will discuss that later.
Coming up: IMO 2008 Problem 3.