# For which $n$ can $\{1,2,…,n\}$ be rearranged so that the sum of each two adjacent terms is a perfect square? [duplicate]

For which numbers $n$ can the sequence $1$ to $n$ be rearranged such that each pair of consecutive terms adds up to a perfect square?

Can this be done on the set of natural numbers as well? Integers? Rationals? ## marked as duplicate by Elaqqad, Watson, amd, Bobson Dugnutt, user223391 Mar 9 '16 at 22:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• Could you put these numbers on a circle? ( I mean can these numbers be put so that the sum of the first and last numbers are a square as well?) – S.C.B. Feb 28 '16 at 23:45
• Am I the only one who finds the animation in the graphic annoying? – Barry Cipra Feb 29 '16 at 0:14
• it is conjectured that there is a solution for all $n>24$ – Elaqqad Feb 29 '16 at 0:41
• @BarryCipra: I think the graphic helped the post get more than 10 upvotes, while this post from exactly a year ago and which is very similar got only 3. I guess some readers are quite visual. :) – Tito Piezas III Feb 29 '16 at 0:59
• oeis.org/A090460 – user217174 Feb 29 '16 at 9:19

## 1 Answer

(Just to summarize things so people don't have to jump from MSE, MO, OEIS, SO.)

This is a rather interesting question, but there are two previous MSE posts that have already covered it. Post 1 (MSE) asks for which $n$ we can arrange {$1,2,\dots n$} so that the sum $S^k$ of every two adjacent numbers is a square (or $k=2$). A commenter pointed A090461 hence,

$$n = 15,16,17,23,25,26,27,\dots,\infty$$

so it is conjectured for all $n>24$. That, in turn, was inspired by Post 2 (MSE) which was the general case, but focused on sums $S^k$ for $k>2$. For $k=3$, the OP gave an example as $n=305$.

Post 3 (MO) gives an example for $k=4$ as $n=9641$. It was also a cyclic arrangement; that is, the first and last entries also have a sum $S^k$.

P.S. Re MYXMYX's question here if there is a cyclic arrangement for $n=35$ for squares, MJD found there are a whopping $17175$ possible arrangements, so chances are good. By the update below, OEIS says there are $57$ ways to do it.)

• (Update.) Let $n$ have all adjacent pair-sums as $S^2$. Then the number of circular arrangements $m_c$ starting with $n=32$ is given by A071984 as, $$\begin{array}{|c|c|}\hline n&\text{# of}\;m_c\\32&1\\33&1\\34&11\\35&57\\ \hline\end{array}$$ – Tito Piezas III Feb 29 '16 at 17:58