I am trying to prove the following: If $p$ is prime, then the only solutions of the congruence $x^2 \equiv x$ (mod $p$) are those integers $x$ such that $x \equiv 0$ (mod $p$) or $x \equiv 1$ (mod $p$).
My approach is this. Given $x^2 \equiv x$ (mod $p$), then $x^2 - x = pk$ for some $k \in \mathbb{Z}$. So $x(x-1) = pk \equiv 0$ (mod $p$). It follows by the fact that the integers are an integral domain, $x \equiv 0$ or $x \equiv 1$ are the only two solutions to $x^2 \equiv x$ (mod $p$).
Is this a valid proof?
The proof is valid, but here you re using the fact that the integers mod p (set of residue classes mod p) form an integral domain!