# Nonzero integers mod $p$ - showing exactly half are perfect squares

I've been scratching my head lately over this question:

Suppose that $p$ is an odd prime number. An element $x$ of $\mathbb{Z}_p$ is called a perfect square in $\mathbb{Z}_p$ if there is an element $u$ in $\mathbb{Z}_p$ such that $x = u^2$. Show that exactly half of the nonzero elements of $\mathbb{Z}_p$ are perfect squares.

I didn't know what perfect squares meant, but after doing some independent research, the term can also be coined as "quadratic residues". How should one approach this question, keeping in mind that in need to show that exactly half of the nonzero elements of $\mathbb{Z}_p$ are perfect squares?

• Why do you say you didn't know what "perfect squares" meant? The first sentence in the question is a precise definition of the term. – Erick Wong Mar 15 '17 at 18:20

There are $p-1$ non-zero elements of $\mathbb{Z}_p$, and since $p$ is an odd prime, the number $p-1$ is even. Group these elements according to what their square is. For example, in $\mathbb{Z}_7$, we have $$1^2=1\qquad 2^2=4\qquad 3^2=2\qquad 4^2=2\qquad 5^2=4\qquad 6^2=1$$ and therefore we would group the six non-zero elements of $\mathbb{Z}_7$ into the three groups $$\underbrace{1,6}_{\text{square is 1}}\qquad \underbrace{2,5}_{\text{square is 4}}\qquad \underbrace{3,4}_{\text{square is 2}}$$ Note that the number of groups is equal to the number of perfect squares (since we grouped the elements precisely according to when their squares are the same).

Can you prove that, for any odd prime $p$, each of the groups has exactly two elements, and therefore that there are exactly $\frac{p-1}{2}$ groups?

Hint: In the familiar case of real numbers, if $x>0$, which two numbers are there whose square is $x$?

Map $$(\mathbf Z/p\mathbf Z)^\times$$ to the non-zero squares $$(\mathbf Z/p\mathbf Z)^{\times\,2}$$ by $$\varphi\colon x\mapsto x^2$$. Each quadratic polynomial in a field has at most two roots, and actually $$\varphi^{-1}(\varphi(x))=\{x,-x\}$$.

Thus, by the Shepherd's principle, $$\Bigl\lvert (\mathbf Z/p\mathbf Z)^{\times\,2}\Bigr\rvert=\frac{p-1}2\enspace \text{and}\quad\Bigl\lvert (\mathbf Z/p\mathbf Z)^{\times}\smallsetminus (\mathbf Z/p\mathbf Z)^{\times\,2}\Bigr\rvert=\frac{p-1}2.$$

Shepherds' principle:

Let $$X,Y$$ be two sets and $$f:X\longrightarrow Y$$ be a surjective map such that, for any $$y\in Y, \:\bigl|f^{-1}(y)\bigr|=r$$. Then $$|X|=r\times|Y|.$$