TITLE: On the number of quadratic residues $\pmod{pq}$ where$p$ and $q$ are odd primes.
QUESTION [7 upvotes]: I have read that the formula for the number of quadratic residues $\pmod{pq}$ for odd primes $p$ and $q$ is $\frac{(p-1)(q-1)}{4}$. Is this the case, and if it is, why is it the case and how would one going about proving it? More generally, is there a formula for the number of quadratic residues for any composite modulus $m$ (and if so, why is it so and how would I prove that the formula holds)?

REPLY [3 votes]: This answer isn't as good as André Nicolas's answer, because he made his very accessible while I'm going to be slightly more abstract. However, if you want to understand the number of quadratic residues for general composite modulus $m$, then this is the way to go about it.
First of all, the Chinese remainder theorem says (among other things) that the (abelian) multiplicative group $(\mathbb Z/pq\mathbb Z)^\times$ is isomorphic to the direct product $(\mathbb Z/p\mathbb Z)^\times \times (\mathbb Z/q\mathbb Z)^\times$.
Next, the existence of primitive roots modulo primes tells us that these individual multiplicative groups are cyclic; that is, $(\mathbb Z/p\mathbb Z)^\times \cong \mathbb Z/(p-1)\mathbb Z$ (where the latter is an additive abelian group) and $(\mathbb Z/q\mathbb Z)^\times \cong \mathbb Z/(q-1)\mathbb Z$. Since we're switching from multiplicative notation to additive notation, sqaruing elements in $(\mathbb Z/p\mathbb Z)^\times$ corresponds to doubling elements in $\mathbb Z/(p-1)\mathbb Z$.
So the squares in $(\mathbb Z/pq\mathbb Z)^\times$ (that is, the quadratic residues modulo $pq$) correspond to the elements of $\mathbb Z/(p-1)\mathbb Z \oplus \mathbb Z/(q-1)\mathbb Z$ where both "coordinates" are even. And there are exactly $\frac{p-1}2 \frac{q-1}2$ of these.
To do the general case, you'd still use the Chinese remainder theorem; at the second step, you'd use the existence of primitive roots modulo any odd prime power (and the slight complication André mentioned when $8\mid m$); at the third step, you'd use what you know about cyclic groups.