$Z(r)$ is a field iff the number is prime Could somebody help me to solve it?

Prove that $Z(r)$ is a field iff the number is prime. 

I have known that for every number $n > 0$ of $Z$, $Z(n)$ is a commutative ring.
Thanks a lot!
 A: I am assuming that, by $Z(n)$, you mean the ring $\Bbb{Z}/\Bbb{nZ}$, or the ring of integers modulo $n$. Since you know that $Z(n)$ is a commutative ring, all that's lacking is inverses.


*

*If $r$ is composite with a non-trivial divisor $a$, then $a \cdot \frac{r}{a} = 0$ in the ring, and you get zero divisors.

*If $r$ is prime, use the Euclidean algorithm to construct an inverse for a given element modulo $r$.

If $r$ is prime and $0 < a < r$ is given, it is clear that $\gcd{(a, r)} = 1$. Hence using the Euclidean algorithm, we can find integers $m$ and $n$ for which $$ma + nr = 1$$ In particular, we will see that $ma \equiv 1 \pmod{r}$, so that $m$ is a multiplicative inverse of $a$ in $Z(r)$. For more, a good search term would be "Bezout's Theorem."
On the other hand, when $r$ is compositive and $a$ is a non-trivial factor of $r$, we see that $a \cdot (r/a) = 0$ in the ring, implying that we have zero divisors. More particularly, $a$ can't have a multiplicative inverse if it's a zero divisor (prove this!).
