Why (Zn,*), integers modulo n under multiplication, is a group if and only if n is prime?

Is it true that $(\Bbb Z_n,\cdot)$, integers modulo $n$ under multiplication, is a group if and only if $n$ is prime? If it's true, why? How can I prove it?

• Let's say $n$ has two nontrivial factors, $n=ab$. What happens when you multiply $a$ and $b$? – Matt Samuel Dec 12 '15 at 17:47
• (Oh, you also have to exclude $0$ if you want it to be a group for prime $n$). – Matt Samuel Dec 12 '15 at 17:48
• $\mathbb{Z}_n$ is a group with respect to multiplication only for $n=1$. Perhaps you want to exclude $0$. – egreg Dec 12 '15 at 18:02
• The statement is false if you don't exclude the 0. The statement is true if you do exclude the 0. – fleablood Dec 12 '15 at 18:42

Note that $\mathbb{Z}_n=\mathbb{Z}/n\mathbb{Z}$ is never a group with respect to multiplication, unless $n=1$.
This is because $$ is not invertible, whenever $n>1$. Note: I denote by $[x]$ the equivalence class of $x\in\mathbb{Z}$ under congruence modulo $n$.
If we instead consider $\mathbb{Z}_n\setminus\{\}$ under multiplication, then the set is empty for $n=1$ and it is not even a semigroup for composite $n>1$; indeed, if $n=ab$, with $1<a<n$ and $1<b<n$, we have $$[a][b]=[ab]=[n]=$$ so the set is not closed under multiplication.
Only primes then remain for investigation. If $n$ is prime and $[a]\ne$, then $p\nmid a$ and so $\gcd(a,p)=1$. Therefore the Bachet-Bézout theorem provides $b$ and $c$ such that $ab+pc=1$ and we found the multiplicative inverse $[b]$ of $[a]$.
Remark that this also proves that, for $[x],[y]\ne$, the product $[x][y]\ne$, so the set is closed under multiplication.