Example 2 Consider a permutation $\left\{a_{1}, a_{2}, \cdots, a_{n}\right\}$ of $\{1,2, \cdots, n\}$. If
\[
\begin{array}{l}
a_{1}, a_{1}+a_{2}, a_{1}+a_{2}+a_{3}, \cdots, \\
a_{1}+a_{2}+\cdots+a_{n}
\end{array}
\]
contains at least one perfect square, then the permutation is called a "quadratic permutation."

Find all positive integers $n$ such that every permutation of $\{1,2, \cdots, n\}$ is a quadratic permutation.
(2002, Iran Mathematical Olympiad)
Let $a_{i}=i(1 \leqslant i \leqslant n), b_{k}=\sum_{i=1}^{k} a_{i}$.
If $b_{k}$ is a perfect square, set $b_{k}=m^{2}$, that is,
$$
\begin{array}{l}
\frac{k(k+1)}{2}=m^{2} . \\
\text { Then } \frac{k}{2}<m, \text { and } \\
b_{k+1}=\frac{(k+1)(k+2)}{2} \\
=m^{2}+k+1<(m+1)^{2} .
\end{array}
$$

Therefore, $b_{k+1}$ is not a perfect square.
By swapping $a_{k}$ and $a_{k+1}$, from the previous proof, the sum of the first $k+1$ terms is not a perfect square, and the sum of the first $k$ terms is $m^{2}+1$, which is also not a perfect square.
Thus, repeating the above process, for the sequence
$$
b_{1}, b_{2}, \cdots, b_{n}
$$

when a term is a perfect square, swap that term with the next adjacent term, resulting in a non-square sequence, unless $k=n$, i.e., $b_{n}$ is a perfect square, then
$$
\frac{n(n+1)}{2}=\sum_{i=1}^{n} i=m^{2} \text {. }
$$

This is the problem of transforming a triangular formation into a square formation mentioned at the beginning, which can be converted into the Pell equation
$$
x^{2}-2 y^{2}=1 \text {. }
$$

From Example 1, the solution is $x_{k}+\sqrt{2} y_{k}=(3+2 \sqrt{2})^{k}$, that is,
$$
\begin{array}{l}
\left\{\begin{array}{l}
x_{k}+\sqrt{2} y_{k}=(3+2 \sqrt{2})^{k}, \\
x_{k}-\sqrt{2} y_{k}=(3-2 \sqrt{2})^{k}
\end{array},(k=1,2, \cdots, n) .\right. \\
\text { Hence } x=2 n+1=\frac{(3+2 \sqrt{2})^{k}+(3-2 \sqrt{2})^{k}}{2} .
\end{array}
$$

Thus, all positive integers $n$ satisfy
$$
n=\frac{(3+2 \sqrt{2})^{k}+(3-2 \sqrt{2})^{k}-2}{4},
$$

where, $k=1,2, \cdots, n$.