TITLE: How find the postive $m,n$,such $a^n\equiv 1\pmod m$
QUESTION [6 upvotes]: Find all positive integer pairs $(m,n)$ with $m,n \ge 2$ such that for all $a\in\{1,2,\cdots,n\}$, $$a^n\equiv 1\pmod m$$

If $(a,m)=1$, Euler's Theorem tells us that 
$$a^{\phi(m)}\equiv 1\pmod m.$$
So one family of solutions is $(n,m) = (\phi (m), m)$. Is it possible to describe all families?

REPLY [4 votes]: A proof based in the roots of $X^n-1$

Answer: The only pairs satisfying your statement are $(p,p-1)$ for primes $p$

Given a pair of integers $(m,n)$ such that $n>1$ suppose that for every $k\in\{1,\cdots,n\}$ we have:
$$k^n\equiv 1 \mod m\tag1$$
As noticed by Barry Cipra $n$ must be smaller than $p$ the smallest prime divisor of $m$ because $p^{n}\not\equiv 1\mod m$ hence $n<p$, And as consequence of $(1)$the roots of $x^n-1$ in $\Bbb Z_p$ are exactly $1,\cdots,n$. 
Now let's prove that $n\geq p-1$, by contradiction, assume that $n<p-1$:

If $n$ is even then $p-1$ is another root of $x^n-1$ in $\Bbb Z_p$ which is absurd.
If $n$ is odd then $n+1=2a$ with $a,2\leq n$ hence $n+1$ is another root of the polynomial ($2^n\equiv 1\mod p $ and $a^n\equiv 1\mod p$ implies $(n+1)^n\equiv 1\mod n$) which is absurd.

As a conclusion $n=p-1$. Now given another prime $q$ which divides $m$, we can prove using the same method (as we did for $p$) that $n\geq q-1$ and because $n=p-1$ we have $p=q$.
If $m$ is divisible by $p^2$, we know that:
$$(p-1)^{p-1}\equiv -p(p-1)+1 \mod p^2 $$
which is absurd because $(p-1)^{p-1}\equiv 1\mod m\equiv 1\mod p^2$ hence $m=p$
Finally we proved that $n=p-1$ and $m=p$ is aprime