Statement:

\[ a^{m} \equiv a ~(\textrm{mod}~m)\]

Where, $m$ is a prime. In other words, $a^{m} - a$ is a multiple of $m$. If $ m \nmid a$, then we have,

\begin{equation} \label{FLT1} a^{m - 1} \equiv 1 ~(\textrm{mod}~m) \end{equation}

Modular Multiplicative Inverse using FLT

When we have, $m \nmid a$, \eqref{FLT1} can be rewritten,

\[ a \cdot a^{m -2} \equiv 1 ~(\textrm{mod}~m) \]

Therefore, $a^{m-2} ~(\textrm{mod}~m)$ is the modular multiplicative inverse of $a~(\textrm{mod}~m)$. We can calculate $a^{m - 2}~(\textrm{mod}~m)$ by Exponentiation By Squaring.