Find all $n$ with $\!\bmod n\!:\, a\,$ invertible $\Rightarrow a^{-1} \equiv a,\,$ i.e. $a^2\equiv 1$ 
Find all positive integers $n$ such that $a \equiv a^{-1} \pmod{n}$ for all invertible $a$ modulo $n$.

I found that $n = 1,2,4,6,8,12,24$ satisfy this. How can we prove that these are all of them?
 A: Equivalently, you are asking that $a^2\equiv 1\pmod{n}$ for any invertible $a$ mod $n$.  By the Chinese remainder theorem, it suffices to consider the case that $n=p^d$ is a prime power.  If $p$ is odd and $p^d\neq3$, then $a=2$ is invertible mod $p^d$ but $a^2=4\not\equiv 1\pmod{p^d}$.  If $p=2$ and $d>3$, then $a=3$ is invertible mod $p^d$ but $a^2=9\not\equiv 1\pmod{p^d}$.
So if $n$ has the property you state, then the only possible odd prime factor of $n$ is $3$ (and $3^2\not\mid n$) and the highest power of $2$ dividing $n$ is at most $2^3$.  That is, $n\mid 24$, which is exactly the numbers on your list together with $n=3$ (which is also an example and is missing from your list).
A: notice that this would imply $a^2\equiv 1$ for all $a$ coprime to $n$. Notice that $5$ does not work because $2^2$ is not $1\bmod 5$, we conclude that if $5|n$ then $n$ does not work, by taking an invertible residue class that is $2\bmod 5$.
Finally, if $5\nmid n$ then we should have that $5^2 \equiv 1 \bmod n$, which implies $n$ is a divisor of $24$.

Note: to see that if $5\mid n$ there is an integer $x$ that is invertible $\bmod n$ and congruent to $2\bmod 5$ we can write $n = 5^am$ with $5\nmid m$ and take a solution to the system:
$x \equiv 2 \bmod 5^a$
$x \equiv 1 \bmod m$
A: The hypothesis implies that $U(n)$ has exponent $2$.
By the Chinese remainder theorem, the exponent of $U(n)$ is given by the 
Carmichael function
$$
\lambda (n)=\operatorname {lcm}(\lambda (p_{1}^{{a_{1}}}),\;\lambda (p_{2}^{{a_{2}}}),\dots ,\lambda (p_{k}^{a_{k}}))
$$
where
$$
\lambda (p^a)=
\begin{cases}
\;\;\varphi(p^a) &\mbox{if } p\ne 2\\
\tfrac12\varphi(p^a)&\text{if }p=2
\end{cases}
$$
Therefore, $\varphi(p_i^{a_i})=2$ for all odd prime factors of $n$, which implies that $p=3, a=1$ is the only possible candidate, and also that $n$ at most a factor $2^8$.
These restrictions give the list you have found.
A: $\,\overbrace{{\rm if}\,\ 5\!\nmid\! n\,\ {\rm then}\,\ n\,|\, \color{#90f}{24}\!=\! 5^2\!-\!1}^{\large \text{by hypothesis}},\,$ else $\,5\!\mid\! n =\!\! \overbrace{\color{#0a0}2^{\large j}\color{#c00}k}^{\large {\rm odd}\  \color{#c00}k}\!, \,$ &  $\,(\color{#0a0}2\!+\!5\color{#c00}k)^{\large 2}\!\not\equiv 1\bmod{5},\,$ so  $\not\equiv 1\bmod n.\,$ $\small\bf QED$
