20. Consider a permutation $\left(a_{1}, a_{2}, \cdots, a_{n}\right)$ of $\{1,2, \cdots, n\}$. If at least one of $a_{1}, a_{1}+a_{2}, \cdots, a_{1}+a_{2}+\cdots+a_{n}$ is a perfect square, it is called a "square permutation". Find all positive integers $n$ such that every permutation of $\{1,2, \cdots, n\}$ is a "square permutation".
(19th Iranian Mathematical Olympiad (Third Round))
Solution: Let $a_{i}=i, 1 \leqslant i \leqslant n, b_{k}=\sum_{i=1}^{k} a_{i}$. If $b_{k}=m^{2}$, i.e., $\frac{k(k+1)}{2}=m^{2}$, then $\frac{k}{2}<m$, and $\frac{(k+1)(k+2)}{2}=$ $m^{2}+k+1<(m+1)^{2}$. Therefore, $b_{k+1}$ is not a perfect square.

If $a_{k}$ and $a_{k+1}$ are swapped, then the sum of the first $k$ terms of the new sequence is $b_{k}+1$, which is not a perfect square. Repeating this process, we can obtain a non-square sequence, unless $k=n$.
$$
\begin{array}{l}
\text { If } \frac{n(n+1)}{2}=\sum_{i=1}^{n} i=m^{2}, \text { then } \\
(2 n+1)^{2}-2(2 m)^{2}=1 .
\end{array}
$$

Let $x=2 n+1, y=2 m$, we get the Pell equation $x^{2}-$ $2 y^{2}=1$. We know that $x_{0}=3, y_{0}=2$ is a solution. If $(x, y)$ is a solution, then $x+\sqrt{2} y=(3+2 \sqrt{2})^{k}, x-\sqrt{2} y=(3-2 \sqrt{2})^{k}, k=1,2$, $\cdots$, then
$$
\begin{array}{l}
x=\frac{1}{2}\left[(3+2 \sqrt{2})^{k}+(3-2 \sqrt{2})^{k}\right], \\
n=\frac{1}{4}\left[(3+2 \sqrt{2})^{k}+(3-2 \sqrt{2})^{k}-2\right], \\
k=1,2, \cdots .
\end{array}
$$