# Numbers represented as two different sums of squares

This is an interesting question I came across, and it does not look that easy:

$365$ can be written as a sum of $2$ consecutive squares and also $3$ consecutive squares:

$$\large 365 = 14^2 + 13^2 = 12^2 + 11^2 + 10^2$$

What is the next number with this property? Give the last $3$ digits of the number.

The squares cannot be zero.

(I have no idea what is the deal with "last $3$ digits" part, but this is the original form of the problem)

• This boils down to integer roots of the polynomial $$p(k,n) = k^2 + (k+1)^2 - n^2 - (n+1)^2 - (n+2)^2$$ – AlexR Sep 30 '14 at 7:07
• As Yves has hinted, this does not contain a worked solution, just an answer: The next number is $35645 = 133^2 + 134^2 = 108^2 + 109^2 + 110^2$, and in fact the increasing sequence $(a_n)$ of all such numbers satisfies the Lucas-like recurrence relation $a_n=99(a_{n−1}−a_{n−2})+a_{n−3}$. The sequence is given at oeis.org/A007667 – Travis Sep 30 '14 at 7:21
• Thanks, I am flabbergasted to see 99 in the recurrence formula! :) Why 99? – VividD Sep 30 '14 at 7:25
• @Travis: Note that, $$1^5+2^5+\dots+\color{brown}{13}^5 = 1001^2$$ $$1^5+2^5+\dots+\color{brown}{133}^5 = 971299^2$$ and which is not coincidence. Kindly see my answer. – Tito Piezas III Jan 12 '16 at 15:09
• @VividD: I hope you enjoy the surprises below. :) – Tito Piezas III Jan 12 '16 at 16:05

The problem reduces to, $$k^2+(k+1)^2=(n-1)^2+n^2+(n+1)^2\tag1$$

or simply,

$$2k^2+2k-1 = 3n^2\tag2$$

Making a quadratic into a square is a well-studied subject. The complete solution is given by,

$$k = \frac{3p^2\pm6pq+4q^2}{3p^2-2q^2}$$

where $3p^2-2q^2=1$. We can transform this condition into a more conventional Pell equation by using the substitutions (the trick is described in this post),

$$p,\,q = u^2+4uv+6v^2,\quad u^2+6uv+6v^2$$

and $u,\pm v$ solve,

$$u^2-6v^2=1$$

Example.

Substitute $\displaystyle k = \frac{3p^2\pm6pq+4q^2}{3p^2-2q^2}$ into the LHS of $(1)$ and we get,

$$F_{\pm}(u,v):= k^2+(k+1)^2 = \frac{45 p^4 \pm 108 p^3 q + 120 p^2 q^2 \pm 72 p q^3 + 20 q^4}{(3p^2-2q^2)^2}$$

bearing in mind that $p,\,q = u^2+4uv+6v^2,\; u^2+6uv+6v^2$ and $u^2-6v^2=1$. Thus,

$$F_-(1,0) = 5$$ $$F_+(1,0) = 365$$ $$F_+(5,-2) = 35645$$ $$F_-(5,-2) = 3492725$$ $$F_-(5,2) = 342251285$$ $$F_+(5,2) = 33537133085$$

which are indeed the first few terms of the sequence A007667.

First surprise.

The $k$ are,

$$k =1, 13, 133, 1321, 13081, 129493,\dots$$

which is sequence A031138 and also defined as,

$$1^5+2^5+3^5+\dots+k^5 = y^2$$

Example:

$$1^5+2^5+3^5+\dots+13^5 = 1001^2$$

Second surprise.

The $n$ are,

$$n = 1, 11, 109, 1079, 10681, 105731,\dots$$

which is A054320 though more interestingly (as A253475),

$$x=\frac{n+1}{2} = 1, 6, 55, 540, 5341, 52866, 523315,\dots$$

with a complementary sequence A054318,

$$y = 1, 5, 45, 441, 4361, 43165, 427285,\dots$$

then,

$$x^2 + (-x + 1)^2 = y^3 + (-y + 1)^3$$

$$4x(x\pm1)+1 = \text{square}$$

$$6y(y-1)+1 = \text{square}$$

Thus, the rather simple original equation turns out to involve relations between second, third, and fifth powers.