# Can any number of squares sum to a square?

Suppose

$$a^2 = \sum_{i=1}^k b_i^2$$

where $$a, b_i \in \mathbb{Z}$$, $$a>0, b_i > 0$$ (and $$b_i$$ are not necessarily distinct).

Can any positive integer be the value of $$k$$?

The reason I am interested in this: in a irreptile tiling where the smallest piece has area $$A$$, we have $$a^2A = \sum_{i=1}^k b_i^2A$$, where we have $$k$$ pieces scaled by $$b_i$$ to tile the big figure, which is scaled by $$a$$. I am wondering what constraints there are on the number of pieces.

Here is an example tiling that realizes $$4^2 = 3^2 + 7 \cdot 1^2$$, so $$k = 8$$.

• Wouldn't $k = 2$ be a counterexample? Commented Dec 7, 2019 at 13:57
• @MichaelSeifert No, $5^2 = 1\cdot 4^2 + 1\cdot 3^2$. Commented Dec 7, 2019 at 13:59
• It might be a little less confusing to phrase this request as the values of $k$ for which $a^2 = \sum_{i = 1}^k b_i^2$, where the various $b_i$ values may or may not be distinct. For example, $4^2 = 3^2 + 1^2 + 1^2+ 1^2+ 1^2+ 1^2+ 1^2+ 1^2.$ Commented Dec 7, 2019 at 14:02
• To make the problem nontrivial, we must assume that the $b_i$ are not zero.I think that the case $k_1=k_2=\cdots k_n=1$ is always solvable in positive integers which would already solve the problem. Commented Dec 7, 2019 at 14:05
• Note that for any even $k \geq 4$, we have a solution of the form $(n+1)^2 = n^2 + (2n + 1) \cdot 1^2$; and any as you noted, any Pythagorean triple solves $k = 2$. The interesting cases are when $k$ is odd. Commented Dec 7, 2019 at 14:15

"Is any $$k$$ possible?" An easy route to "Yes": You know from the Pythagorean theorem that two squares can add to a perfect square. $$c^2=a^2+b^2$$

$$c^2$$ must be either odd or even. If odd, it is the difference between two consecutive squares. $$c^2=2n-1=n^2-(n-1)^2$$ If even, $$c^2$$ is divisible by $$4$$ and is also the difference between two squares. $$c^2=4n=(n+1)^2-(n-1)^2$$ So in either case, $$c^2$$ equals the difference between two squares. $$c^2=r^2-s^2 \\ r^2=c^2+s^2=a^2+b^2+s^2$$ Here, $$r^2$$ is the sum of three squares.

This can be repeated indefinitely, increasing by one the number of squares in the sum which adds to a square. There is no limit to the number of squares that can be accumulated in the sum.

• Actually, since an odd square is always $1$ modulo $4$, the $n$ in $c^2=2n-1$ is also always odd, so starting from odd $c^2$ always gives odd squares (e.g. starting from $5^2=4^2+3^2$, we get $5^2 = 13^2-12^2$, $13^2 = 85^2-84^2$...).
– JiK
Commented Dec 8, 2019 at 1:49
• @JiK It's possible to start with a non-primitive Pythagorean triple such as $10^2=8^2+6^2$, so some provision for even squares must be considered. Commented Dec 8, 2019 at 4:11

Yes, $$k$$ can be arbitrary. Define a sequence$$a_1:=3,\,a_{k+1}:=\frac12\left(a_k^2+1\right)$$ of odd positive integers (since $$\frac12((2n+1)^2+1)=2(n^2+n)+1$$), so\begin{align}a_{k+1}^2-a_k^2&=\frac14\left[(a_k^2+1)^2-4a_k^2\right]\\&=\left[\frac12(a_k^2-1)\right]^2\end{align}is a perfect square. Now define$$b_1:=3,\,b_{k+1}:=\frac12(a_k^2-1)$$so $$a_k^2=\sum_{i=1}^kb_i^2$$ for all positive integers $$k$$. The sequence $$a_n$$ is called the Pythagorean spiral or OEIS A053630.

This holds far more generally. OP is the special case $$S$$ = integer squares, which is $$\rm\color{#0a0}{closed}$$ under multiplication $$\,a^2 b^2 = (ab)^2,\,$$ and has an element that is a sum of $$\,2\,$$ others, e.g. $$\,5^2 = 4^2+3^2$$.

Theorem  If $$\,S\,$$ is a set of integers $$\rm\color{#0a0}{closed}$$ under multiplication then
\qquad\qquad \begin{align}\phantom{|^{|^|}}\forall\,n\ge 2\!:\text{ there is a }\,t_n\in S\,&\ \text{that is a sum of \,n\, elements of \,S }\\[.1em] \iff\! \text{ there is a }\,t_2\in S\,&\ \text{that is a sum of \,2\, elements of \,S\!}\\ \end{align}

Proof $$\ \ (\Rightarrow)\$$ Clear. $$\ (\Leftarrow)\$$ We induct on $$\:\!n.\,$$ The base case $$\,n = 2\,$$ is true by hypothesis, i.e. we are given that $$\,\color{#c00}{a = b + c}\,$$ for some $$\,a,b,c\in S.\,$$ If the statement is true for $$\:\!n\:\!$$ elements then

\begin{align} s_0 &\,=\, s_1\ \ +\ s_2\ + \cdots +s_n,\ \ \ \ \,{\rm all}\ \ s_i\,\in\, S\\ \Rightarrow\,\ s_0a &\,=\, s_1 a + s_2 a + \cdots +s_n\color{#c00} a,\ \ \color{#0a0}{\rm all}\ \ s_ia\in S \\[.1em] &\,=\, s_1 a + s_2 a + \cdots + s_n \color{#c00}b + s_n \color{#c00}c \end{align}\qquad\qquad

so $$\,s_0 a\in S\,$$ is a sum of $$\,n\!+\!1\,$$ elements of $$\,S,\,$$ completing the induction.

Remark  A comment below asks for further examples. Let's consider some "minimal" examples. $$S$$ contains $$\,a,b,c\,$$ wth $$\,a = b + c\:$$ so - being closed under multiplication - $$\,S\,$$ contains all products $$\,a^j b^j c^k\ne 1$$. But these products are already closed under multiplication so we can take $$S$$ to be the set of all such products. Let's examine how the above inductive proof works in this set.

\begin{align} \color{#c00}a &= b + c\\ \smash{\overset{\times\ a}\Longrightarrow}\qquad\qquad\, a^2 = ab+\color{#c00}ac\, &= b(a+c)+c^2\ \ \ {\rm by\ substituting}\,\ \color{#c00}a = b+c\\ \smash{\overset{\times\ a}\Longrightarrow}\ \ a^3 = b(a^2+ac)+ \color{#c00}ac^2 &= b(a^2+ac+c^2)+c^3 \\[.4em] {a^{n}} &\ \smash{\overset{\vdots_{\phantom{|^|}\!\!}}= \color{#0a0}b (a^{n-1} + \cdots + c^{n-1}) + c^{n}\ \ \text{ [sum of \,n\!+\!1\, terms]}}\\[.2em] {\rm by}\ \ \ a^{n}-c^{n} &= (\color{#0a0}{a\!-\!c}) (a^{n-1} + \cdots + c^{n-1})\ \ \ {\rm by}\ \ \color{#0a0}{b = a\!-\!c} \end{align}\quad\ \ \

So the proof's inductive construction of an element that is a sum of $$n+1$$ terms boils down here to writing $$\,a^n\,$$ that way using the above well known factorization of $$\,a^n-c^n\,$$ via the Factor Theorem.

By specializing $$\,a,b,c\,$$ one obtains many examples, e.g. using $$\,5^2,4^2,3^2$$ as in the OP then $$S$$ is set of squares composed only of those factors, and the $$\,n\!+\!1\,$$ element sum constructed is

$$25^n =\, 9^n + 16(25^{n-1}+ \cdots + 9^{n-1})$$

• This is a very clear generalization. Would be lovely if you could add one or two unexpected examples other than squares (I could only think of "multiple of m" and other powers which are not so interesting.) Commented Dec 10, 2019 at 0:28
• +1 this is also constructive for OP's needs, I think. Commented Dec 10, 2019 at 2:34
• (I said "other powers" but realized this is wrong.) Commented Dec 10, 2019 at 3:22
• @Herman I added a Remark showing some simple examples. Commented Dec 11, 2019 at 17:59
• @R.. Yes, it is indeed constructive, e.g. see the Remark I appended. Commented Dec 11, 2019 at 19:17

Here is a geometric solution (for $$k > 5$$).

The following are solutions for 6, 7, and 8 squares.

We can replace a square in each of these with four equal size squares to find a tiling with 3 more squares, so we can get 9, 10, and 11 squares. Repeating this we can get any number of squares larger than 5.

I show one iteration below:

• Beautiful and simple. Well done. Commented Dec 9, 2019 at 20:54
• So the unit square is defined as whatever the smallest square is? Commented Dec 9, 2019 at 21:53
• @Cruncher yes indeed. Commented Dec 9, 2019 at 22:18
• Yes, when we split a square into 4 we are halving its side length, which would yield nonintegers if the side length was odd. To get around that we first scale everything by 2 to ensure all square side lengths (= summands) are even. Then it's precisely the algebraic transformation I mentioned above. Commented Dec 9, 2019 at 23:16
• I added an answer which highlights the key algebraic properties at the heart of the matter. Commented Dec 10, 2019 at 0:14

Yes.

For $$k = 2$$: $$3^2 + 4^2 = 5^2$$

For $$k > 2$$:
Start with a solution for $$k-1$$
Multiply both sides by $$5^2$$
Replace one $$(5a)^2$$ on the left with $$(3a)^2$$ + $$(4a)^2$$.

$$3^2 + 4^2 = 5^2$$
$$15^2 + 20^2 = 25^2$$
$$9^2 + 12^2 + 20^2 = 25^2$$ (k = 3)

$$45^2 + 60^2 + 100^2 = 125^2$$
$$27^2 + 36^2 + 60^2 + 100^2 = 125^2$$ (k = 4)

Repeat until k is as desired.

It is known enough the generalization of Phytagorean triples which let us to say YES. Just as for $$k=2$$ two parameters are needed, for $$k\gt2$$ we need $$k$$ arbitrary parameters $$t_1,t_2\cdots,t_k$$ so we have the identity easily verified $$(t_k^2-t_1^2-t_2^2\cdots-t_{k-1}^2)^2+(2t_1t_k)^2+(2t_2t_k)^2+\cdots+(2t_{k-1}t_k)^2=(t_1^1+\cdots+t_k^2)^2$$.

(Note that for $$k=2$$ we have the quite known parameterization of Phytagorean triples).

Solutions exist for every $$k>0$$. The simplest forms use most of the $$b_n$$ values as $$1$$. I will list them as "$$b_*$$". I suspect there are infinitely many distinct answers for each $$k\ge2$$, but I can't prove it.

if $$k = 2n$$ (k is even) and large enough ($$k\ge4$$ or $$n>1$$):

• $$a = n$$
• $$b_1 = n-1$$
• $$b_* = 1$$

\begin{align} \sum_{i=1}^k b_i^2 & = (n-1)^2 + (2n-1)\cdot1^1 \\ & = n^2 - 2n + 1 + 2n - 1 \\ & = n^2 \\ & = a^2 \\ \end{align}

if $$k = 4n + 1$$ and large enough ($$k\ge9$$ or $$n>1$$)

• $$a = n+1$$
• $$b_1 = n-1$$
• $$b_* = 1$$

\begin{align} \sum_{i=1}^k b_i^2 & = (n-1)^2 + ((4n+1)-1)\cdot1^1 \\ & = n^2 - 2n + 1 + 4n \\ & = n^2 +2n + 1 \\ &= (n + 1)^2 \\ & = a^2 \\ \end{align}

if $$k = 4n + 3$$

• $$a = 2n+3$$
• $$b_1 = 2n+2$$
• $$b_2 = 2$$
• $$b_* = 1$$

\begin{align} \sum_{i=1}^k b_i^2 & = (2n+2)^2 + 2^2 + ((4n+3)-2)\cdot1^1 \\ & = 4n^2 + 8n + 4 + 4 + 4n + 1 \\ & = 4n^2 + 12n + 9 \\ &= (2n + 3)^2 \\ & = a^2 \\ \end{align}

The only values that don't work with these patterns are $$k$$ = 1, 2, or 5.

For $$k=1$$, $$a=b_1$$ for any values.

For $$k=2$$, we have we have a well known case, with minimal value $$5^2=4^2+3^2$$

For $$k=5$$, the minimal value is $$4^2=3^2+2^2+1^2+1^2+1^2$$

• Maybe I am missing something. Sup $k = 9$, so $n = 2$, and $a = 3, b_1 = 2$, then we have $3^2 = 2^2 + 5\cdot 1$, but then $k = 1 + 5 = 6$ ... ? Commented Dec 8, 2019 at 18:23
• @Herman If k=9, a=3, $b_1$=1, so we have $3^2 = 1^2 + 8 \cdot 1$ Commented Dec 8, 2019 at 20:22
• Ah, I miscalculated. Got it now :+1: Commented Dec 8, 2019 at 23:13
• You can maybe improve the answer by showing some calculations to save the reader from having to do them. Commented Dec 8, 2019 at 23:23

Many of the other answers (based on extending smaller values of $$k$$) yield a fairly large value for the LHS. It’s worth pointing out that we actually know a great deal about the set of integers representable as the sum of $$k$$ nonzero squares.

See, for instance, this other answer, where it is shown that every integer $$\ge 34$$ is the sum of five positive squares. Immediately, by padding with $$1$$s, we can extend this to

For $$k\ge 5$$, every integer $$> k+28$$ can be written as the sum of $$k$$ nonnegative squares.

Therefore, we can just choose $$a^2$$ to be the first square greater than $$k+28$$, which makes $$a^2 \le k + 2\sqrt k + O(1)$$, which makes $$a \le \sqrt k + 1 + O(k^{-1/2}).$$ This basically optimal as clearly $$a \ge \lceil \sqrt k\rceil^2$$.

We might be able to shave down the constant $$28$$ somewhat by increasing the lower bound on $$k$$, but it can’t be reduced all the way to $$0$$ because of the gap between the first two nonzero squares $$1$$ and $$4$$. There must be some constant $$C>0$$ that is the optimal replacement for $$28$$ for all $$k\ge k_0$$ (I wouldn’t be surprised if it is already optimal).

Yes, any number of squares can be a perfect square. Take the example of Pythagorean triples generated by the formula with a table of triples shown below it where $$n$$ is a set and where $$k$$ is a set member.

$$$$A=(2n-1)^2+2(2n-1)k\qquad B=2(2n-1)k+2k^2\qquad C=(2n-1)^2+2(2n-1)k+2k^2$$$$ $$\begin{array}{c|c|c|c|c|c|c|} n & k=1 & k=2 & k=3 & k=4 & k=5 & k=6 \\ \hline Set_1 & 3,4,5 & 5,12,13& 7,24,25& 9,40,41& 11,60,61 & 13,84,85 \\ \hline Set_2 & 15,8,17 & 21,20,29 &27,36,45 &33,56,65 & 39,80,89 & 45,108,117 \\ \hline Set_3 & 35,12,37 & 45,28,53 &55,48,73 &65,72,97 & 75,100,125 & 85,132,157 \\ \hline Set_{4} &63,16,65 &77,36,85 &91,60,109 &105,88,137 &119,120,169 & 133,156,205 \\ \hline Set_{5} &99,20,101 &117,44,125 &135,72,153 &153,104,185 &171,140,221 & 189,180,261 \\ \hline \end{array}$$ Since $$3^2+4^2=5^2$$, we can replace the $$5$$ in $$5,12,13$$ with $$3,4$$ so $$3^3+4^2+12^2=13^2$$. The value of $$A$$ can be any odd number greater than $$1$$ so there is always a triple where side-A of one equals side-C of another. Extending to a couple more squares, $$3^2+4^2+12^2+84^2+132^2+12324=12325$$. The process can be extended to infinite numbers of squares summed.

Let me know if you would like to know how to find "extensions".