# When is a sum of consecutive squares equal to a square?

We have the sum of squares of $n$ consecutive positive integers: $$S=(a+1)^2+(a+2)^2+ ... +(a+n)^2$$ Problem was to find the smallest $n$ such, that $S=b^2$ will be square of some positive integer. I found an example for $n=11$. Now, I'm trying to prove, that if $2<n<11$ there is't any solution. So I need some help with this: If $n,a,b \in \mathbb{N}$ and $n<11$ prove that equation

$$n\cdot a^2 + n(n+1)\cdot a + \frac{1}{6}n(n+1)(2n+1)=b^2$$

can't be solved. Or if I'm wrong, find counterexample.

The only idea I have is: to consider the remains $\operatorname{Mod}[b^2,n]$ and $\operatorname{Mod}[\frac{1}{6}n(n+1)(2n+1),n]$. For each $2<n<11$, but it is very long.

-
I wrote a little program. There are definitly no solutions for $1<a<100.000.000$, $2<n<11$. –  user38034 Sep 5 '12 at 11:07
I'm considering remains of $b^2 : n$. I prove that Mod$[b^2,n]$ $\neq$ Mod$[\frac{1}{6}n(n+1)(2n+1),n]$ for n={3,4,5,7,9}. Think by this way we can prove for n=6,8,10 also. I thought there is some methods in number theory to solve this equation. For (a,b) it is Diophantine equation with fixed n. Isn't it? –  Mike Sep 5 '12 at 11:34
See oeis.org/A001032 and the references there. –  lhf Sep 5 '12 at 11:46
Regarding @user38034's little program, note that there is a solution for $n=11$, namely $18^2 + 19^2 + \cdots + 28^2 = 77^2$. –  MJD Sep 5 '12 at 12:06
@MJD Without any program easy to find 2 solutions started from a+1=18, and a+1=38. Problem was how to find for which n this equation can be solved. –  Mike Sep 5 '12 at 12:25

In general, there are $n$ consecutive squares that add to a square if and only if the following Diophantine equation has solutions:

$$x^2-ny^2=\frac{n(n-1)(n+1)}{3}$$

with the added parity condition that $y$ and $n$ are different parities. The value $y$ is just the sum of the first and last element of the sequence, so $$\frac{y-n+1}{2}$$ is the beginning of the sequence.

When $n$ is not square, then the nice thing about Pell-like equations is that if there is one solution with the above parity condition, there are infinitely many. In particular, then there is always a sequence of consecutive positive numbers if there is any consecutive sequence of integers.

If $n$ is a perfect square, then there is a solution if and only if $(n,6)=1$. It is not always the case that you can find consecutive squares of positive numbers in this case. But we can get a solution $m,m+1,\dots,m+n-1$ with $m=\frac{(n+1)(n-25)}{48}$ when $n$ a perfect square, which gives positive solutions except when $n=1$ and $n=25$. But $n=1$ obviously has positive solutions, so the only problem case is $n=25$. There is no positive solution when $n=25$, only a non-negative solution: $0^2+1^2\dots+24^2$ is a square.

When $n$ is not a perfect square, this condition gets harder, but the Pell-like nature of the equation gives us a way to find some solutions. For exmaple, $u^2-nv^2=n(n-1)$ has a trivial solution, so if $n+1$ is divisible by $3$ then we can find a solution to the above equation of $w^2-nz^2 = \frac{n+1}{3}$ yields a solution to the above, and it turns out you can easily show in that case that the solution satisfies the parity condition. In particular, if $n=3w^2-1$, then $(w,z)=(w,0)$ is a solution, so we know we have infinitely many non-square values of $n$, and, in particular, $n=11$ when $w=2$.

Necessary conditions when $n$ is not a square:

A. Factor $n=a^{2}b$, with $b$ square-free, then:

1. If $2 \mid a$, then $2 \mid b$
2. If $3 \mid a$, then $3 \mid b$
3. $3$ is a square $\pmod{b}$. (Alternatively, the only primes that divide $b$ are $2$, $3$, and primes of the form $12k \pm 1$.)
4. If $3 \mid b$, then $b \equiv 6 \pmod{9}$

B.

1. If $3 \mid n+1$, then $\frac{n+1}{3}$ is the sum of two perfect squares
2. If $3 \nmid n+1$, then $n+1$ is the sum of two perfect squares

These can be used to exclude $n=3,...,10$:

• $3$ violates $A.4.$
• $4$ is a square and $(4,6)\neq 1$
• $5$ violates $A.3.$.
• $6$ violates $B.2$.
• $7$ violates $A.3.$
• $8$ violates $B.1.$
• $9$ is a square not relatively prime to $6$.
• $10$ violates $B.2.$

See here for some more details and some ways to explicitly construct such $n$.

I don't have sufficient conditions. The smalles number that satisfies the above conditions but for which there is no solution is $n=842$.

It is easier to come up with necessary and sufficient conditions for the question of whether there exists an arithmetic progression of length $n$ such that the sum of the squares is a square. Indeed, if $y$ and $n$ are the same parity in the above equation, that amounts to a sequence of $n$ consecutive odd numbers whose squares add up to a square.

-

Below is a reasonable (but not very illuminating) proof. Put $S_n(x)=\sum_{k=1}^{n} (x+k)^2$. Note that it is also true that for $2<n<11$, $S_n(x)$ is never a square modulo $n^2$, and $S_n(x)$ is also never a square modulo $900$. Perhaps this will inspire others to produce more intelligent proofs.

Here it goes :

$$\begin{array}{ccll} S_3(x) & \equiv & 3x^2+12x+14 \equiv 2 & {\sf mod} \ 3 \\ S_4(x) & \equiv & 4x^2+20x+30 \equiv 2 & {\sf mod} \ 4 \\ S_5(x) & \equiv & 5x^2+30x+55 \equiv 2 \ \text{or} \ 3 & {\sf mod} \ 4 \\ S_6(x) & \equiv & 6x^2+42x+91 \equiv 3 & {\sf mod} \ 4 \\ S_7(x) & \equiv & 7x^2+56x+140 \equiv 3,8,11 \ \text{or} \ 12 & {\sf mod} \ 16 \\ S_8(x) & \equiv & 8x^2+72x+204 \equiv 2,5,6 \ \text{or} \ 8 & {\sf mod} \ 9 \\ S_9(x) & \equiv & 9x^2+90x+285 \equiv 6 & {\sf mod} \ 9 \\ S_{10}(x) & \equiv & 10x^2+110x+385 \equiv 5,10 \ \text{or} \ 20& {\sf mod} \ 25 \\ \end{array}$$

Each time, we see that $S_n(x)$ is never a square for the given modulus.

-