This article only contains results with few proofs. All arguments can be made with basic number theory, with a little knowledge.
For what values of n does there exist n consecutive perfect squares that add up to a perfect square?
This reduces to a Pell-like equation equation:
(1) x2-ny2 = (n-1)n(n+1)/3
With the added condition:
n and y have different parity
The value of y corresponds to twice the midpoint of the sequence m,m+1,...,m+(n-1) whose squares add up to a square. (If y and n are the same parity, then the solution corresponds to a sequence of n consecutive perfect odd squares that add up to a square.)
When n is a perfect square, there is a solution if and only if n is relatively prime to 6.
Given m a perfect square relatively prime to 6, we can find a solution y=(n2-49)/24 which results in the first term of our sequence being:
m = (n+1)(n-25)/48
One of the nice properties of Pell-like equations is that if you have solutions to two Pell-like equations:
u2-nv2 = A w2-nz2 = B
Then we can find a solution to:
s2-nt2 = AB
This is convenient in our case because there is a very easy solution to:
u2-nv2 = n(n-1)
Namely, u=n, v=1.
This means that if (n+1)/3 is an integer, and we can find a solution to:w2-nz2 = (n+1)/3
We'd have a solution. Solving for n, we get:
n = (3w2-1)/(3z2+1)
Whenever you have a representation of n in this form, you can find a solution to (1) with the correct parity condition. (In fact, y=w.)
The case where z=0 gives us the simplest infinite set of non-square values of n, namely, n = 3w2-1.
The smallest n of this form which cannot be represented with z=0 is 23.
Interestingly, when z>0, we can can find:
is also a solution to (1), but the solution only satisfies the parity condition if w is odd. For example, we can take any solution to:n' = 3z2n
w2-2z2=1
which has infinite solutions with z>0, and get a solution:
n' = 6z2
A similar, but more complicated complement when z>0 is:
n'' = 3(w+z)2 - n
But in this case, the solution to (1) only satisfies the parity condition if w is even.
For example:
n = 11 = (3w2-1)/(3z2+1) w=20, z=6. n'' = 3*(w+z)2 - 11 = 2017
In fact, we have trivial solutions to these Pell-like equations:
r2-ns2 = -n (r=0, s=1) r2-ns2 = 1-n (r=1, s=1)
So, once we have a solution to:
w2-nz2 = (n+1)/3
We can multiply by -n on both sides to get a solution to the equation:
(*) r2-ns2 = -n(n+1)/3 r=nz, s=w
But if we rewrite (*) as a quadratic equation in n, we get:
n2 - (3s2-1)n + 3r2 = 0
Since we have one integer solution to this monic integer quadractic equation, we know that there has to be another solution, and n' is that other solution. At this point you need to show that the resulting solution to (1) satifies the parity condition, but that's not hard.
Similarly, for n'', we first find a solution to:
(**) r2-ns2 = -(n-1)(n+1)/3 r=w+nz, s=w+z
and again rewrite it as a monic equation in n and find the complement solution to that equation.
That's why there are two "complement" values - there's one dual for each of the equations.
(*) and (**) will have solutions that are not originally from an n of the form (3w2-1)/(3z2+1).
Necessary conditions when n is not a square:
A. Factor n=a2b, with b square-free, then 1. If a is divisible by 2, then b is divisible by 2 2. If a is divisible by 3, then b is divisible by 3 3. b is only divisible by primes 2,3 or 12k±1 4. If b is divisbible by 3, then b ≅ 6 (mod 9) B. 1. If n+1 is divisible by 3, then (n+1)/3 is the sum of two perfect squares 2. If n+1 is not divisible by 3, then n+1 is the sum of two perfect squares
There are, however, values of n which match all these conditions but do not have a solution. The smallest such n is 842. (And yes, it is interesting that 842=292+1, and 841 = 202+212.)
Note that the necessary conditions apply when n is a perfect square. (B) is trivially true, since n+1 is never divisible by three and is obviously the sum of squares. (A.1) and (A.2) coincides with the restriction that n be relatively prime to 6, and (A.3) and (A.4) are true because b=1. So these necessary conditions are sufficient in the case where n is a perfect square.
Extension question: For what n can we find an arithmetic sequence of length n such that the sum of the squares of the values is a perfect square?
In this case, the Pell-like equation is:
(2) x2-ny2 = d2(n-1)n(n+1)/3
Where d is the common difference of the arithmetic sequence.
We also need y to have the same parity as d(n-1), but the parity condition is less relevant, since if we have a solution without the parity condition, we can multiple both sides by 4 and get a solution with the parity condition:
(2x)2-n(2y)2 = (2d)2(n-1)n(n+1)/3
When n is a perfect square, we can always find a solution to (2), and, in particular, we can find a solution with d=gcd(n,6).
For example, when n=4:
62 = (-1)2+12+32+52
With n=9:
242 = (-10)2 + (-7)2 + (-4)2 + (-1)2 + 22 + 52 + 82 + 112 + 142
For a general square, you can start with:
m = (3n+2)(√n-1)/2 + 6 d = 6
This general solution has the advantage that the first term, m is positive for all squares n.
Some of these necessary conditions will seem similar:
A'. Factor n=a2b, with b square-free, then
1. If b and n+1 are both not divible by 3, then b ≅ 1 (mod 3)
2. If b is divisible by 3, then b ≅ 6 (mod 9)
3. 3 is a square, (mod b.) (Alternatively, the only primes that divide
b are 2, 3, and primes of the form 12k +/- 1.)
B'.
1. If n+1 is divisible by 3, then (n+1)/3 is the sum of two perfect squares
2. If n+1 is not divisible by 3, then n+1 is the sum of two perfect squares
It turns out these are sufficient conditions, too.
An equivalent necessary and sufficient condition is that we must be able to write:
(3) n = (u2-3w2)/(v2+3w2)
where all terms must be integers.
This formula can be re-written as:
(3') u2-nv2 = 3(n+1)w2
Alternatively:
(3'') u2 = nv2+3(n+1)w2
You can get from (2) to (3') and back by using the fact that you can write n(n-1) trivially in the form r2-ns2, namely with r=n, s=1. So you can multiply (2) by 9m(m-1) and re-order to get a solution for (3') with w=n(n-1)d.
You get from (3') to (2) by again multiplying both sides of (3) by n(n-1) to get a solution for (2) with d=3w.
For n in the form (3), we can find an m explicitly when d=6w as:
m=(v-3w)n + u + 3w
(This obviously doesn't work when w=0, so we have to find a different solution when n is a perfect square.)
We can add the condition that gcd(v,w)=1 because if they have a common prime factor, then that factor must divide the denominator of (3), and hence the numerator of (3) and hence u as well, and therefore we can remove that factor.
If we add one to both sides of (3), we get:
n+1 = (u2+v2)/(v2+3w2)
This is the "source" of the conditions in (B').
Equation (3'') can be seen as looking for rational solutions to the equation:
nx2 + 3(n+1)y2 = 1
The Hasse-Minkowski theorem gives us the tool for determining when this equation has rational solutions, and the result coincides with (A') and (B').
Alternatively, see: pp. 238-242 of Harvey Cohn: Advanced Number Theory.
For specific pairs (v,w), you get some of the specific examples we have seen. For example, with (v,w)=(1,0)), we get a solution when n is a perfect square. With (v,w)=(0,1), there is a solution when n=3z^2-1 for some z.
The non-squares which satisfy these rules but not the original rules for consecutive integers start with:
52 (m=1003,d=2) 148 (m=-389, d=6) 244 (m=8057, d=6) 276 (m=-241, d=2) 292 (u=104 v=5, w=2) 388 (u=12784, v=649, w=2) 528 (u=552, v=23, w=4) 564 (u=444, v=7, w-10, m=--2231 d=10) 592 (u=208 v=5, w=4) 628 (u=484, v=19, w=2) 708 (u=96,v=1, w=2) 772 (u=71824, v= 2585, w=2) 792 (m=-2296, d=6) 832 (u=448, v=7, w=8) 842 (u=939, v=30, w=7, m=1110, d=7) 852 (m=105,d=2) 964 (u=112, v=1, w=2) 976 (u=20464, v=655, w=4) 996 (u=192, v=5, w=2)
The case of n=842 was the example from the first section which satisfied (A) and (B) but for which no integer solution of (1) can be found. Turns out, it requires d=7.