(OIM 1990-4) Determine the integers $n \in \mathbb{N}$ such that $n^{2} \mid 2^{n}+1$.
The obvious solutions are 1 and 3. Suppose now that $n>1$. At random, consider $p$ the smallest integer that divides $n$. It is clear that $n$ must be odd, and therefore $p$ as well. The hypothesis implies that $2^{n} \equiv -1 \pmod{p}$ and thus that $2^{2n} \equiv 1 \pmod{p}$. Thus, the order of 2 modulo $p$ divides $2n$. But it also divides $p-1$ (by Fermat's little theorem) and by definition of $p$, $\gcd(p-1, n)=1$. Thus we obtain that this order is 1 or 2. In the first case, we find $2 \equiv 1 \pmod{p}$ which is impossible, the second possibility implies that $p=3$. We can therefore write $n=3^l \times k$ and we will determine the possible values of $l$. For this, we factorize

$$
2^{3^l k} + 1 = \left(2^{3^{l-1} k} + 1\right)\left(2^{2 \times 3^{l-1} k} - 2^{3^{l-1} k} + 1\right).
$$

We see that this formula (in particular the left term) is particularly well-suited for induction. We evaluate the right term modulo 9. 2 is of order 6 modulo 9 and its first powers are $2, 4, -1, -2, -4, 1$. Recalling that $k$ is odd, we immediately obtain that

$$
2^{2 \times 3^{l-1} k} - 2^{3^{l-1} k} + 1 \equiv 3 \pmod{9}
$$

Finally, $2^k + 1$ is also divisible by 3, but not by 9, due to the fact that $k$ is even, but not divisible by 3. In conclusion, the 3-adic valuation of $2^{3^l k} + 1$ is exactly $l+1$. But by hypothesis, $3^{2l} \mid 2^n + 1$, thus, the only possibility is that $l=1$.

Now that we have settled the case of 3, we move on to the next prime divisor. Suppose $k \geq 2$, otherwise we have the solution $n=3$. Let $p$ be the smallest divisor of $k$. Thus, $p \geq 5$, and we proceed as before. From $2^{6k} \equiv 1 \pmod{p}$ we deduce that the order of 2 modulo $p$ divides $6l$ but also $p-1$ and thus, by definition of $p$, it must divide 6. It is therefore $1, 2, 3$, or 6. And we have that 2, 4, 8, or 64 is congruent to 1 modulo $p$. Of all these cases, since $p$ is neither 2 nor 3, the only possibility is $p=7$. But 7 never divides $2^n + 1$, indeed the successive powers of 2 modulo 7 are 2, 4, 1. Therefore, there is no other solution.