Let $n \in \mathbb{Z}$ with $n\geq2$, and let $a\in \mathbb{Z}$.
Prove that $[a]_n$ is a unit in $\mathbb{Z}_n$ (i.e. $[a]_n$ has a multiplicative inverse) if and only if $\gcd(a, n) = 1$.
I know for $[a]_n$ to be a unit, there needs to exist an element $[b]_n$ such that $[a]_n[b]_n$=1. I then know we must end up with $ax+ny=1$ for some integers $x$ and $y$. I am not sure how to get here though.
What I have tried: I have tried $[a]_n[b]_n$=1 and from this, going to $(a=qn+x)(b=kn+y)=1$, but I do not think I can go anywhere from this.
Can anyone help, please?