Given n and m, Solve for x : $n ^ x = 1\mod m$

32 Views Asked by At

Given positive integers $n$ and $m$, Find the smallest positive integer $x$ such that $$n ^ x = 1\mod m$$

$m$ is not necessarily prime, So if $m = p_{1}^{a_{1}}p_{2}^{a_{2}}p_{3}^{a_{3}}...p_{k}^{a_{k}}$, I am looking for an algorithm with time complexity $O(a_1a_2a_3..a_k)$ or better.