Solution (source code)

= Solution

The order of $a$ modulo $N$ is the least positive integer $r$ such that
$$
\boxed{a^r\equiv1\pmod N.}
$$
It exists because $a$ is a unit in the finite group $(\mathbb Z/N\mathbb Z)^\times$.