Show that the number of reduced residues $a \mod m$ such that $a^{m-1} \equiv 1 \mod m$ is exactly $$\displaystyle \prod_{p \mid m} \gcd(p-1,m-1).$$
Suppose $f(x) = x^{m−1}−1$ and let $m = p^\alpha_1 \cdots p^\alpha_n$ denote the prime factorization of $m.$ If $p$ is prime, $p \mid m$ and $\alpha \geqslant 1,$ then $f(x)$ has $(m − 1, p − 1)$ roots modulo $p^{\alpha}.$ Thus $f(x)$ has $\displaystyle \prod (m − 1, p − 1)$ roots mod $m.$ Suppose $p \geqslant 3$ or $p = 2$ and $\alpha = 1$ or $2.$ By the generalized Euler criterion, $x^m−1 ≡ 1 \mod p^{\alpha}$ has $k = (m − 1, \phi(p^{\alpha})) = (m-1,p^{\alpha-1}(p-1))$ roots since $1^{\phi(p^{\alpha}/k)} \equiv 1 \mod p^{\alpha}.$ But $k = (m-1,p^{\alpha-1}(p-1)) =(m-1,p-1)$ since $p \mid m$ and hence $p \nmid m−1.$ We are left with the case that $p = 2$ and $\alpha \geqslant 3.$ Since $p = 2 \mid m$ we have that $m − 1$ is odd. Thus $x^{m−1} ≡ a \mod 2^{\alpha}$ has exactly $1$ solution. But in this case $1 = (m − 1, p − 1) = (m − 1, 2 − 1)$ as well. $ \Box$
Above is a elementary number theory proof. Question: How can this be proved using tools from abstract algebra (potentially group/ring theory)?