Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to prove following statement :


Odd prime $p$ is expressible as : $p=x^2+4\cdot y^2$ , $x,y > 0$

if and only if : $p\equiv 1 \pmod {12}$ or $p\equiv 5 \pmod {12}$ .

Similar statements (without a proof) related to the Fermat's theorem on sums of two squares can be found here .

share|cite|improve this question
up vote 3 down vote accepted

This is an immediate consequence of Fermat's theorem that an odd prime $p$ is a sum of two squares if and only if $p \equiv 1$ (mod 4). Such a prime $p$ is congruent to $1$ (mod 3) or $2$ (mod 3). In the former case, $p \equiv 1$ (mod 12), and in the latter case, $p \equiv 5$ (mod 12). Given a prime $p \equiv 1$ (mod 4), express it in the form $a^2 + b^2,$ for positive integers $a$ and $b.$ Now $a$ and $b$ can't both be of the same parity, so assume that $a$ is even and $b$ is odd. If $ab$ is not divisible by $3,$ we have $p \equiv 2$ (mod 3), so $p \equiv 5$ (mod 12). If $ab$ is divisible by $3,$ we have $p \equiv 1$ (mod 3) and so $p \equiv 1$ (mod 12).

share|cite|improve this answer

First to prove for the "only if" clause in a similar method to one found here:

For squares modulo 12 we have {0, 1, 4, 9} as the only possibilities for any $x^2$ (Quadratic residues), while only {0, 4} is valid for any $4\cdot y^2 = (2y)^2$. For primes $p > 12$ modulo 12 we have {1, 5, 7, 11}, the integers coprime to 12, as the only possibilities. Trying all possible options will show that 7 and 11 (mod 12) cannot be formed no matter how you pick the squares, while 1 and 5 are possible due to 1 + 0 (mod 12) and 1 + 4 (mod 12) respectively.

Checking for the remaining primes $p <= 12$ can then be done by hand.

Now noting that both 1 and 5 modulo 12 are equivalent to 1 modulo 4 allows us to apply the very theorem you linked in your question for the "is expressible if" clause, the proof of which is above on Wikipedia.

share|cite|improve this answer

Modulo $12$, the quadratic residues are:

$[1,4,9,4,1,0,1,4,9,4,1]$. Of these, odd residues are $1,9$.

And the residues of the form $4\times i^2 \pmod{12}$ are of the form


Hence, any $\textbf{odd}$ number of the form $(j^2+4\times i^2)$ has to be either $1$ or $5\pmod{12}$, regardless of whether or not it is a prime.

share|cite|improve this answer

HINT $\rm\ (\Rightarrow)\ \ odd\ p\ =\ x^2+4\ y^2\ \Rightarrow\ x\ odd,\ so\ \ mod\ 4\!:\ x\ \equiv\: \pm1\ \Rightarrow\ p\ \equiv\ x^2\:\equiv\ 1 $

Thus $\rm\ p\equiv 1\pmod 4\ \Rightarrow\ p\equiv 1,5,9\pmod{12}\:,\:$ but not $\:9\:$ since $\rm\:3\:|\:p\ \Rightarrow\ p = 3\ne x^2 + 4\ y^2$

$\rm(\Leftarrow)\ $ By Fermat $\rm\: p \equiv 1\pmod 4\: \Rightarrow\ p\: =\: m^2 + n^2\: \Rightarrow\ 2\ |\ m\ \ or\ \:n\ ($else $\rm\: 2\ |\ p = odd^2+odd^2)$

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.