\section{Modular Arithmetic}

\definition{}
$\mathbb{Z}_n$ is the set of integers mod $n$. For example, $\mathbb{Z}_5 = \{0, 1, 2, 3, 4\}$. \par

\vspace{2mm}

Multiplication in $\mathbb{Z}_n$ works much like multiplication in $\mathbb{Z}$: \par
If $a, b$ are elements of $\mathbb{Z}_n$, $a \times b$ is the remainder of $a \times b$ when divided by $n$. \par
\note{For example, $2 \times 2 = 4$ and $3 \times 4 = 12 = 2$ in $\mathbb{Z}_5$}

\problem{}
Create a multiplication table for $\mathbb{Z}_4$:

\begin{center}
\begin{tabular}{c | c c c c}
	$\times$ & 0 & 1 & 2 & 3 \\
	\hline
	0 & ? & ? & ? & ? \\
	1 & ? & ? & ? & ? \\
	2 & ? & ? & ? & ? \\
	3 & ? & ? & ? & ? \\
\end{tabular}
\end{center}





\definition{}
Let $a, b$ be elements of %\mathbb{Z}_n$. \par
If $a \times b = 1$, we say that $b$ is the \textit{inverse} of $a$ in $\mathbb{Z}_n$.

\vspace{2mm}

We usually write \say{$a$ inverse} as $a^{-1}$. \par
Inverses are \textbf{not} guaranteed to exist.

\theorem{}<mod_has_inverse>
$a$ has an inverse in $\mathbb{Z}_n$ if and only if $\gcd(a, n) = 1$ \par

\problem{}
Find the inverse of $3$ in $\mathbb{Z}_4$, if one exists. \par
Find the inverse of $20$ in $\mathbb{Z}_{14}$, if one exists. \par
Find the inverse of $4$ in $\mathbb{Z}_7$, if one exists.

\begin{solution}
	\begin{itemize}
		\item $3^{-1}$ in $\mathbb{Z}_{4}$ is $3$
		\item $20^{-1}$ in $\mathbb{Z}_{14}$ doesn't exist.
		\item $4^{-1}$ in $\mathbb{Z}_{7}$ is $2$
	\end{itemize}
\end{solution}

\vfill


\problem{}
Show that if $n$ is prime, every element of $\mathbb{Z}_n$ (except 0) has an inverse.
\vfill

\problem{}
Show that if $n$ is not prime, $\mathbb{Z}_n$ has at least one element with no inverse.
\vfill

\pagebreak

\problem{}<general_inverse>
In general, how can we find the inverse of $a$ in $\mathbb{Z}_n$? Assume $a$ and $n$ are coprime.\par
\hint{You can find that $34^{-1}$ is $-175$ in $\mathbb{Z}_{541}$ by looking at a previous problem.}

\begin{solution}
	We need an $a^{-1}$ so that $a \times a^{-1} = 1$. \par
	This means that $aa^{-1} - mk = 1$. \par
	Since $a$ and $m$ are coprime, $\gcd(a, m) = 1$ and $aa^{-1} - mk = \gcd(a, m)$ \par
	Now use the extended Euclidean algorithm from \ref{extendedeuclid} to find $a^\star$.
\end{solution}

\vfill

\definition{}
Elements in $\mathbb{Z}_n$ that have an inverse are called \textit{units}. \par
The set of units in $\mathbb{Z}_n$ is called $\mathbb{Z}_n^\times$, which is read \say{$\mathbb{Z}$ mod $n$ cross}.

\problem{}
What is $\mathbb{Z}_5^\times$? \par
What is $\mathbb{Z}_{12}^\times$? \par

\vfill
\pagebreak

