Example 2 Find all positive integers $n$ such that $\frac{2^{n}+1}{n^{2}}$ is an integer.
(31st IMO)
When $n=1,3$, it is obviously true.
When $n \neq 1,3$, let the prime $p$ be the smallest prime factor of $n$.
$$
\begin{array}{l}
\text { By } \frac{2^{n}+1}{n^{2}} \text { being an integer } \\
\Rightarrow p \mid\left(2^{n}+1\right) \\
\Rightarrow p \mid\left(2^{2 n}-1\right) .
\end{array}
$$

But by Fermat's Little Theorem,
$$
p \mid\left(2^{p-1}-1\right) \text {. }
$$

Therefore, by Corollary 2 of [1], we get
$$
p \mid\left(2^{(p-1,2 n)}-1\right) \text {. }
$$

Since the prime $p$ is the smallest prime factor of $n$, it can only be that $(p-1,2 n)=2$.
Thus, $p \mid\left(2^{2}-1\right)$, i.e., $p=3$.
Let $3^{k} \| n$.
Notice that $3 \|\left(2^{2}-1\right)$.
By the lemma, $3^{k+1} \|\left(2^{2 n}-1\right)$.
And $n^{2}\left|\left(2^{n}+1\right) \Rightarrow 3^{2 k}\right|\left(2^{2 n}-1\right)$, so
$$
k+1 \geqslant 2 k \Rightarrow k=1 \Rightarrow 3 \| n \text {. }
$$

Therefore, let $n=3 m$.
If $m \neq 1$, let $q$ be the smallest prime factor of $m$. Hence $q \neq 3$.
Similarly to the previous proof, we get
$$
q \mid\left(2^{(q-1,6 m)}-1\right) \text {. }
$$

Since $(q-1,6 m)=2,6$, then
$$
q \mid\left(2^{2}-1\right) \text { or } q \mid\left(2^{6}-1\right)=7 \times 3^{2} \text {. }
$$

But $q \neq 3$, so it can only be that $q=7$.
However, $2^{n}+1 \equiv 8^{m}+1 \equiv 2(\bmod 7)$, which is a contradiction.
Upon verification, $n=1,3$.