Find all integers $n>0$ such that $n^{2} \mid 2^{n}+1$

## Interesting modulos:
Notice that $n=1$ works. Moreover, since $2^{n}+1$ is always odd, $n$ is odd. Now, suppose $n>1$ and let $p$ be the smallest prime divisor of $n$, and $\omega$ the order of 2 modulo $p$. We need to start the same reasoning as in exercise 8 now, to find $\omega=2$. Indeed, first of all,

$$
1 \leqslant \omega \mid 2^n + 1 \mid 2^{2n} - 1
$$

Since $p \mid 2^{2n} - 1$ and $p \mid 2^{\omega} - 1$, we have $\omega \mid 2n$. Since $p$ is the smallest prime divisor of $n$, $\omega$ must be 1 or 2. But $\omega = 1$ is impossible because $2^1 - 1 = 1$ is not divisible by $p$. Therefore, $\omega = 2$.

This implies $p \mid 2^2 - 1 = 3$, so $p = 3$. Since $n$ is odd, $n$ must have at least one other prime divisor (3 being to the power of 1). Let $p'$ be the second smallest prime divisor of $n$, and $\omega'$ the order of 2 modulo $p'$. We have, similarly, $\omega' \mid 2n$. The second case gives us $p' \mid 2^6 - 1$, in other words, $p' \mid 7 \times 9$. Thus,

$$
p' = 7
$$

The problem is that $2^3 \equiv 8 \equiv 1 \pmod{7}$, so $\omega' \mid 3$ (and it is 3), hence $\omega' \neq 6$. This is absurd. Therefore, $n$ does not admit a second smallest prime divisor. In conclusion, the solutions are $n=1$ and $n=3$.