# When is the sum of consecutive squares a prime?

For what integers $$x$$ do there exist $$x$$ consecutives integers, the sum of whose squares is prime?

I tried use $$1^2+2^2+...+n^2=\frac {n(n+1)(2n+1)}{6}$$

• Do you require the first $x$ squares to sum to a prime? Or do you simply require that $\exists n\in \mathbb{N}$ such that $n^2+\ldots + (n+x-1)^2$ is prime? Apr 21, 2014 at 23:00
• @Nicholas Stull know to which integers $x$, $x$ are consecutive square numbers that generate a prime number. Apr 21, 2014 at 23:07

Let our numbers be $a^2,(a+1)^2,\dots,(a+x-1)^2$. The sum of the squares is $a^2 x+2a(1+\cdots+(x-1))+(1^2+\cdots+(x-1)^2)$.

Note that $a^2 x$ is divisible by $x$, as is $2a(1+\cdots+(x-1))$. So we concentrate on the term $1^2+2^2+\cdots+x^2$. Call this number $N$. By the formula quoted in the post, we have $$6N=(x-1)(x)(2x-1).$$ Suppose that $x\gt 6$. Then $N$ has a factor $d\gt 1$ such that $d\mid x$. We show that $d$ is a proper divisor of $a^2+(a+1)^2+\cdots +(a+x-1)^2$. This is because $$a^2+(a+1)^2 +\cdots +(a+x-1)^2 \gt \left(\frac{x-1}{2}\right)^2,$$ and $\left(\frac{x-1}{2}\right)^2\gt x$ if $x\gt 6$. Thus all candidate $x$ are in the interval from $1$ to $6$.

We can rule out $x=4$, since in that case our sum of squares is even, and clearly cannot be $2$.

We can also rule out $x=5$, because if $x=5$ then $5$ divides $N$, and it is easy to verify that a sum of $5$ consecutive squares must be greater than $5$.

That leaves $x=1$ (no good), $x=2$, $x=3$, and $x=6$. For each of $x=2$, $x=3$, and $x=6$, we can produce examples of a sum of squares of $x$ consecutive integers which is prime. The simplest example for $x=3$ uses the consecutive integers $-1$, $0$, and $1$. The simplest example for $x=6$ uses $-2,-1,0,1,2,3$. There are also examples with all entries positive.

It is not known whether there are infinitely many solutions.

The sum of the squares of the first $x$ consecutive integers, starting from $n+1$, equals $$(n+1)^2+(n+2)^2+\ldots+(n+x)^2=\frac{(n+x)(n+x+1)(2(n+x)+1)}{6}-\frac{n(n+1)(2n+1)}{6}$$ $$=\frac{1}{6}\cdot x\cdot(6n^2+6nx+2x^2+6n+3x+1).$$ For this to be prime we must have $x\mid 6$ or $$6n^2+6nx+2x^2+6n+3x+1\mid6.$$ Solving the quadratic equation $$6n^2+6nx+2x^2+6n+3x+1=c,$$ for $n$ where $c\mid 6$ yields the solutions $$n=-\frac{1}{2}(x+1)\pm\frac{1}{2}\sqrt{3+6c-3x^2},$$ which shows that $c\geq-\tfrac{1}{2}$ and $x\leq\sqrt{1+2c}$, which reduces to $c\in\{2,3,6\}$ and $x\in\{2,3\}$ as $x=1$ is impossible. The only values that yield integral solutions for $n$ are $c=3$ and $x=2$, with solutions $n=0$ and $n=3$ corresponding to the sums of squares $$1^2+2^2=5\qquad\text{ and }\qquad 4^2+5^2=41.$$

Otherwise $x\mid 6$. For $x=2$, $x=3$ and $x=6$ we may take $n=1$ to find $$2^2+3^2=13,\qquad 2^2+3^2+4^2=29,\qquad 2^2+3^2+4^2+5^2+6^2+7^2=139,$$ which are all prime, and $x=1$ is still impossible. Hence the values of $x$ for which there exists $x$ consecutive integers, the sum of whose squares is prime, are $2$, $3$ and $6$.

• Because for n is prime, $x\mid 6$ or $6n^2+6nx+2x^2+6n+3x+1\mid6?$ Apr 21, 2014 at 23:19
• Is this a question? If so, I don't understand what you're asking. Apr 21, 2014 at 23:20
• Minor comment, the sum of the squares of $3$ consecutive integers can be prime, $(-1)^2+0^2+1^2=2$, or if you want positives $2^2+3^2+4^2=29$. Apr 21, 2014 at 23:23
• Thanks, I just noticed, but my battery died. I'll be making some revisions. Apr 21, 2014 at 23:45
• @marcelolpjunior I believe he means, if $\frac{ab}{6}$ is prime, then $a | 6$ xor $b | 6$. Basically one variable (wlog a) divides 6, and the other variable (wlog b) $b = (6/a)\cdot p$ for some prime $p$. Apr 22, 2014 at 3:07

The sum of $$x$$ consecutive squares starting from $$n$$ is $$n^2+(n+1)^2+...+(n+x-1)^2=xn^2+2n\sum_{k=1}^{x-1} k +\sum_{k=1}^{x-1} k^2$$ $$\Rightarrow n^2+(n+1)^2+...+(n+x-1)^2=xn^2+nx(x-1)+\frac{(x-1)x(2x-1)}{6}$$ If $$x\equiv 1,5\ (mod\ 6)\$$ then we have $$(x-1)(2x-1)\equiv0\ (mod\ 6)$$ which means that $$\frac{(x-1)(2x-1)}{6}\$$ is an integer so the sum becomes: $$n^2+(n+1)^2+...+(n+x-1)^2=x(n^2+nx(x-1)+\frac{(x-1)(2x-1)}{6})$$ meaning that if $$x\equiv 1,5\ (mod\ 6)\$$ the sum of the square of x consectuive integers will never be a prime.
If $$x\equiv 0\pmod6\ \text{and}\ x>6$$ then $$\frac {x}{6}$$ will be an integer greater than 1 so we will have: $$n^2+(n+1)^2+...+(n+x-1)^2=\frac {x}{6}(6n^2+6nx(x-1)+(x-1)(2x-1))$$ and again no pirme. In the same fashion if $$x\equiv2\ (mod\ 6)$$ and $$x>2\$$ we take $$\frac{x}{2}$$ as a factor, and if $$x\equiv4\pmod6$$ we take $$\frac{x}{2}$$ again as a factor and finally if $$x\equiv3\pmod6\$$ and $$x>3\$$ we take $$\frac{x}{3}$$ as a factor. Now we need to consider tha cases in which x = 2, 3, 6: if $$x = 2$$ then we have $$1^2+2^2=5$$ which is a prime if $$x = 3$$ then we have $$2^2+3^2+4^2=29$$ which is prime and if $$x = 6$$ then we have $$2^2+3^2+4^2+5^2+6^2+7^2 = 139$$ which is again a prime. So the answer for this problem will be 2, 3 and 6