Theorem:
An integer $k$ in $\mathbb{Z}_{n}$ is a generator of $\mathbb{Z}_{n}$ If and Only if $gcd\left ( n,k \right )=1$
My problem lies with proving the "If" condition and here is my attempt:
Suppose $gcd\left ( n,k \right )=1$
Observe $\frac{n}{gcd\left ( n,k \right )}=\frac{n}{1}=n$
But $\frac{n}{gcd\left ( n,k \right )}=\left | a^{k} \right |=\left | \left \langle a^{k} \right \rangle \right |=\left | \mathbb{Z}_{n} \right |$
But note that $\mathbb{Z}_{n}$ is an additive group so $\left | \left \langle ka \right \rangle \right |=\left | \mathbb{Z}_{n} \right |$
This implies $\left \langle ka \right \rangle=\mathbb{Z}_{n}$
Evidently, we are done if $a=1$ but I am unable to justify this.
A useful hint is appreciated. Thanks in advance.
By the Bezout Identity, there exist integers $x$ and $y$ such that $xk+yn=1$. Without loss of generality we may take $x\ge 0$.
So for any $a$, we have $(ax)k\equiv a\pmod{n}$.