Find all positive integers $m$ with the property that every unit $a$ in $\mathbb{Z}_m$ satisfies $a^2 = 1$. I am having troubles solving this exercise. I've tried using Euler's Theorem but I'm not too experienced with it. It also that, until $m=8$, the only integers that satisfy this are powers of $2$. Any help?
 A: You already made an important, though incomplete  observation.
For non-powers of $2$, let $p$ be an odd prime dividing $m$, say $k\ge1$ and $m=p^kr$ with $p\nmid r$.
Note that $2$ is a unit $\bmod p^k$ and $1$ is a unit $\bmod r$. By the Chinese Remainder Theorem, there exists $a$ with  $a\equiv 2\pmod{p^k}$ and $a\equiv 1\pmod r$. Then $a$ is a unit $\bmod m$ and $a^2\equiv 4\not\equiv 1\pmod {p^k}$, so $a^2\not\equiv 1\pmod m$ -- except perhaps when $p^k=3$.
We conclude that the only possible $m$ with the desired poperty are of the form $m=2^k$ or $m=3\cdot 2^k$ with $k\ge 0$.
But we also cannot have $m=2^k$ with  $k\ge 4$ because in that case $3$ is a unit $\bmod {2^k}$ but its square is $9\not\equiv 1\pmod m$.
By another invocation of the Chinese Remainder Theoram or by explicitly looking at the unit(!) $a=5\bmod 3\cdot 2^4$ we see that $m=3\cdot 2^4$ also requires $m\le 3$. Now check the remaining cases $m=1,2,3,4,8,12,24$ carefully again: for which of these does the property hold?
A: Hint If $d|m$ then every unit in $\mathbb Z_d$ also satisfies $a^2=1$.
Hint 2 If $p$ is prime and $a^2 =1 \pmod{p}$ then $a = \pm 1 \pmod{p}$
