[Math] Show that if $p$ is prime, then the only solutions of the congruence $x^2 \equiv x \pmod p$ are those integers $x$ such that $x=0$ or $1 \pmod p$

elementary-number-theorymodular arithmeticpolynomialsprime numbers

Show that if p is prime, then the only solutions of the congruence $x^2\equiv x\pmod p$ are those integers $x$ such that $x\equiv \text{$0$ or $1$}\pmod p$.

I can't even begin to prove this question.

Best Answer

$$x^2\equiv x\!\!\!\pmod p\,\overset{\rm def}\Rightarrow\, p\mid \color{#c00}x(\color{#0a0}{x-1})$$

Since $p$ is a prime, Euclid's Lemma $\Rightarrow\,\color{#c00}{p\mid x}\ \ {\bf or}\ \ \color{#0a0}{p\mid x-1}$

$$\ \ \Rightarrow\ \color{#c00}{x\equiv 0}\ \ {\bf or}\ \ \color{#0a0}{x\equiv 1}\!\!\pmod p$$

Clearly both are roots of $\,x^2-x= x(x-1),\,$ hence they are the complete set of roots.

Remark $ $ The final "root checking" step is needed to rule out the possibility of extraneous roots due to the use of unidirectional $(\Rightarrow)$ inferences above. In fact all arrows hold bidirectionally, i.e. they are equivalences $(\!\!\iff\!\!),\,$ so we could eliminate the final checking step by using bidirectional inferences everywhere (see here for more on such).