Solution (source code)

= Solution
{c}

<Fermat's little theorem> states that for a prime $p$ and any integer $a$,
$$
\boxed{a^p\equiv a\pmod p.}
$$
If $p\nmid a$, the equivalent multiplicative form is $a^{p-1}\equiv1\pmod p$.