When is a sum of consecutive squares equal 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.
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:
- If $2 \mid a$, then $2 \mid b$
- If $3 \mid a$, then $3 \mid b$
- $3$ is a square $\pmod{b}$. (Alternatively, the only primes that divide $b$ are $2$, $3$, and primes of the form $12k \pm 1$.)
- If $3 \mid b$, then $b \equiv 6 \pmod{9}$
B.
- If $3 \mid n+1$, then $\frac{n+1}{3}$ is the sum of two perfect squares
- 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.