When is $1^5 + 2^5 + \ldots + n^5$ a square?

The general solution to $$m^2 = \frac{1}{12}(2n^6+6n^5+5n^4−n^2)$$ is $$m = \frac{n(n+1)}{2} y, \quad n = (x-1)/2$$ where $$x+\sqrt{6} y = (3+\sqrt{6}) (5+2 \sqrt{6})^k$$ for some integer $k$. Here are the first few values $$\begin{array}{|r|l|l|l|l|} \hline k& x & y & n & m\\ \hline 0& 3& 1& 1& 1 \\ 1& 27& 11& 13& 1001\\ 2& 267& 109& 133& 971299 \\ 3& 2643& 1079& 1321& 942162299 \\ 4& 26163& 10681& 13081& 913896491101\\ \hline \end{array}$$

The values of $x$, $y$ obey the recursions $$x_{k+1} =10 x_k - x_{k-1}$$ $$y_{k+1} =10 y_k - y_{k-1}$$ There are more complicated recursions for $n$ and $m$, but I didn't work them out.


As several answers have already done, start by factoring $$m^2 = \frac{1}{12}(2n^6+6n^5+5n^4−n^2) = \frac{1}{3} \left( \frac{n(n+1)}{2} \right)^2 (2n^2+2n-1)$$ So $$2n^2 + 2n -1 = 3 y^2$$ where $y = m \left( \frac{n(n+1)}{2} \right)^{-1}$.

Completing the square: $$(2n+1)^2 - 3 = 6 y^2.$$ So we want to solve $$x^2-6 y^2 = 3$$ with $x$ odd.

This is a Pell like equation. The best way to think about Pell's equations is to think in the ring $\mathbb{Z}[\sqrt{6}]$. For an element $a+b \sqrt{6}$ in this ring, the norm $N(a+b \sqrt{6})$ is $a^2-6 b^2$. Norm is multiplicative, meaning that $N((a_1 + b_1 \sqrt{6}) (a_2 + b_2 \sqrt{6})) = N(a_1+b_1\sqrt{6}) N(a_2 + b_2 \sqrt{6})$. We want to find elements $x+y\sqrt{6}$ with $N(x+y\sqrt{6})=3$.

Notice that $N(5+2 \sqrt{6}) = 1$, so, if $N(x+y \sqrt{6})=3$, then $N((x+y \sqrt{6}) (5+2 \sqrt{6})^k)=3$ for any integer $k$. We will eventually be showing that all solutions to $N(x+y\sqrt{6})=3$ are of the form $x+y \sqrt{6} = \pm (3+\sqrt{6})(5+2 \sqrt{6})^k$.

In general, for $D>0$ any nonsquare, there is always some $(u_0,v_0)$ (the fundamental solution of Pell's equation) so that all solutions to $N(u+v \sqrt{D})=1$ are of the form $u+v \sqrt{D} = \pm (u_0 + v_0 \sqrt{D})^n$. In our setting, $(u_0, v_0) = (2,5)$. For any $K$, there finitely many pairs $(x_1, y_1)$, $(x_2, y_2)$, ..., $(x_r,y_r)$ such that all solutions to $N(x+y \sqrt{D})=K$ are of the form $x+y \sqrt{D} = (x_i+y_i \sqrt{D}) (u_0+v_0 \sqrt{D})^k$ for some $i$ and $k$.

We want to show that, in our case, $r=1$ and we can take $(x_1,y_1) = (3,1)$.

Brute force approach: Let $(x,y)$ be a solution to $N(x+y \sqrt{6}) = 3$ with $x$ and $y>0$. Find a nonnegative integer $k$ such that $$(5+2 \sqrt{6})^k < x+y \sqrt{6} < (5+2 \sqrt{6})^{k+1}.$$ This is always possible, since $\lim_{k \to \infty} (5+2 \sqrt{6})^k=\infty$. Notice that $(5+2 \sqrt{6})^{-1} = 5-2 \sqrt{6}$. So the coefficients of $(x+y \sqrt{6})(5+2 \sqrt{6})^{-k}$ are integers; call them $x_0$ and $y_0$. So $$1 < x_0+y_0 \sqrt{6} < 5+2 \sqrt{6} \ \mbox{and} \ N(x_0+y_0 \sqrt{6})=3$$ Also, we have $$x_0-y_0 \sqrt{6} = 3/(x_0+y_0 \sqrt{6})$$ so $$3/(5+2 \sqrt{6}) < x_0-y_0 \sqrt{6} < 3.$$ Adding these together $$\frac{1}{2} \left( 1+\frac{3}{5+2 \sqrt{6}} \right) < x_0 < \frac{1}{2} \left( (5+2 \sqrt{6})+3 \right)$$ or $$0.6 < x_0 < 5.9.$$ Trying $x_0 = 1$, $2$, $3$, $4$, $5$, we quickly discover the only possibility is $x_0=3$, $y_0=1$. So $x+y \sqrt{6} = (3+\sqrt{6})(5+2 \sqrt{6})^k$.

Slick solution Let $I$ be the ideal generated by $x+y \sqrt{6}$ in the ring $\mathbb{Z}[\sqrt{6}]$. Then $\mathbb{Z}[\sqrt{6}]/I$ has order $3$, so $I$ is a prime ideal containing $(3)$. The prime $3$ ramifies in $\mathbb{Z}[\sqrt{6}]$ so there is only one such prime. Clearly, $(3+\sqrt{6})$ is such a prime, so any other solution to $N(x+y \sqrt{6})=3$ must be such that the ideals $(x+y \sqrt{6})$ and $(3+\sqrt{6})$ are equal. So $x+y \sqrt{6} = (3+\sqrt{6})*\mbox{unit}$, and the units in this ring are $\pm (5+2\sqrt{6})^k$.

Where the recursions come from: Let $u = 5+2 \sqrt{6}$. The minimal polynomial of $u$ is $u^2-10u+1=0$. So $u^{k+1} = 10 u^k -u^{k-1}$, implying that $(5+2 \sqrt{6})u^{k+1} = 10(5+2 \sqrt{6})u^k -(5+2 \sqrt{6})u^{k-1}$ and thus that $(x_{k+1} + y_{k+1} \sqrt{6}) = 10(x_k + y_k \sqrt{6}) - (x_{k-1} + y_{k-1} \sqrt{6})$.


If $$a=1+2+3+\cdots+n$$ then $$ 1^5+2^5+3^5+\cdots+n^5 = \frac{4a^3-a^2}{3}, $$ so now the question is: when is that a square?


This is OEIS A031138, which lists some more and says $a(n) =11\cdot(a(n-1)-a(n-2)) + a(n-3) \\ a(n)=-1/2+((3-\sqrt 6)/4)\cdot(5+2\sqrt 6)^n+((3+\sqrt 6)/4)\cdot(5-2\sqrt 6)^n$