Smallest $n >1$ such that $a^n = a$ in $\mathbb{Z}/m\mathbb{Z}$ for all $a$ A necessary condition for such an $n$ to exist is that $m$ be square-free. However, is it sufficient? If yes, how do you find the smallest such $n$?
Examples: In $\mathbb{Z}/6\mathbb{Z}$ $n = 3$ works: working mod 6, we have $$1^3 = 1, 2^3 = 8 \equiv 2, 3^3 = 27 \equiv 3, 4^3 = 64 \equiv 4, 5^3 = 125 \equiv 5.$$
Similarly, in $\mathbb{Z}/10\mathbb{Z}$ $n = 5$ works. Note that $ 6 = 2 \cdot 3$ and $10 = 2 \cdot 5$ are both square-free.
If $n$ is not square free, say $n = 45 = 3^2 \cdot 9$, then we can divide $n$ be some prime whose square divides $n$ to get a number $a$ (in this case $45/3 = 15$), and $a$ to any power $n > 1$ is always 0 mod n, so in particular $a^n$ will never be $a$ mod $n$.
Now consider $m = 1309 = 7 \cdot 11 \cdot 17$. Is there an $n > 1$ such that $1^n = 1, \ldots, 1308^n = 1308$ (mod 1309)?
 A: If $m = p_1p_2 \cdots p_k$, then the smallest such $n$ will be
$$
1 + \lambda(m) = 1 + \operatorname{lcm}(p_1 -1,\dots,p_k-1).
$$
To see that this is the case, it suffices to note that, by the Chinese Remainder theorem, we have
$$
a^n \equiv a \pmod {m} \iff  a^n \equiv a \pmod {p_i} \text{ for } i = 1,\dots,k.
$$
A: By Fermat's Theorem,and since for every prime there exists a generator of the multiplicative gorup, if $m$ is prime, then $n=m$ itself is the smallest exponent such that
$$a^n \equiv a \pmod m$$
Given now a squarefree composite $m=p_1\cdot p_2\cdot \dots\cdot p_k$, let $s = lcm(p_i-1) +1$. Take now any $0\le a<m$ and inspect the remainder modulus $p_i$
$$
a \equiv a_i \pmod {p_i}
$$
and notice that
$$
a^s \equiv a_i^s = a_i^{(p_i-1)r}a_i\equiv a_i \pmod {p_i}.
$$
by CRT (Chinese remainder theorem), you find that $a^s \equiv a \pmod m$. To prove that $s$ is the least possible, take $g_i$ a generator of $\mathbb Z_{p_i}^\times$ and notice that if $g_i^n\equiv g_i\pmod m$ then
$$
 g_i^n \equiv g_i\pmod {p_i} \implies p_i-1 | n-1
$$
for every $i$. As a consequence, $lcm(p_i-1)|n-1$, so either $s$ or $1$ is the least possible exponent. But you wanto $n>1$.
