For example, given the following modular equation: $$7^m \equiv 1\ (\text{ mod } 13); \quad (7,13)=1$$ By hard working, we can find the solution: $$7^{12} \equiv 1\ (\text{ mod } 13)$$
From my observation, the solution seems to exist for all $a,n \text{ where } (a,n)=1$.
But, I can't come up with any proof. So the question is,
Given integer $a, m, n$, where $(a,n)=1$, Is the following statement always solvable?
$$a^m \equiv 1\ (\text{ mod } n)$$
And if always true or for the true cases, given $a\text{ and }n$ what would be the practical way to find the solution? (Something better than brute-forcing all the values)
Thanks in advance,
Yes. That is Euler's theorem:
So the least $m$ such that $a^m\equiv 1\mod n$ (the
orderof $a$ modulo $n$) is a divisor of $\varphi(n)$.Note: the value of the totient function is easy to calculate: if $n=p_1^{r_1}\dotsm p_k^{r_k}$ is the decomposition of $n$ as a product of distinct primes, then $$\varphi(n)=p_1^{r_1-1}(p_1-1)\dotsm p_k^{r_k-1}(p_k-1).$$