Copyright © University of Cambridge. All rights reserved.

Let $n$ be a whole number. When is it possible to write $n$ as a sum of two squares, say $n=a^2+b^2$, or as a sum of three squares, say $n=a^2+b^2 +c^2$, or as a sum of four squares, and so on? Of course, $a$, $b$, $c$, $\ldots$ are also meant to be whole numbers here. We can also ask whether there is any convenient test to decide whether $n$ is the sum of one square; that is, whether $n$ is itself a square number, say $n=a^2$. In this article we shall mention some of the interesting answers to these questions. The proofs, which belong to the subject called Number Theory, are too difficult to be given here, but take a look at the article written by Tom Sanders, aged 16.

Although there seems to be no easy test to decide when $n$ is a square number, it is easy to give a test to decide when an even whole number $n$ is not a square number. Suppose that $n$ is even and $n=a^2$. Then $a$ must be even (for if $a$ is odd, then so is $a^2$), so that $a^2$ is divisible by $r$. Thus if $n$ is even and a square number, then $4$ divides $n$ exactly. This shows, for example, that the number $68792734815298359030284382$ (which is too big to put into your calculator) is not a square number. Why does it show this? Well, this number is of the form $100m+82$ and as $100$ is divisible by $4$, we see that $n$ is divisible by $4$ if and only if $82$ is (and it is not). Now you might like to write down some other (very large) numbers that are not square numbers. Can you see why if $n$ is divisible by $3$ but not by $9$ then $n$ is not a square number? (Try some examples of this.) What can you say about numbers divisible by $5$ but not by $25$?

Now let us consider writing $n$ as the sum of two squares. There is much we can say about this, but first we need to know about the idea of a prime number. A whole number is a prime number if it has no factors other than itself and $1$; for example, the first seven prime numbers are $2$, $3$, $5$, $7$, $11$, $13$, $17$. Now every whole number can be written as a product of prime numbers, and each prime number is either $2$, or an odd number of the form $4k+1$, or an odd number of the form $4k+3$; for example

$$350=2\times 5^2\times 7=2\times (4+1)^2\times (4+3)$$

$$490=2\times 5\times 7^2=2\times (4+1)\times (4+3)^2$$

$$2450=2\times 5^2\times 7^2=2\times (4+1)^2\times (4+3)^2$$

Given a whole number $n$, look at all of the different prime factors of the form $4k+3$ (ignoring the other prime factors) and also the number of times that they occur; if every one of these prime factors occurs an even number of times then $n$ can be written as a sum of two squares; if not, then $n$ cannot be written as the sum of two squares. (Another way of saying this is that $n$ can be written as the sum of two squares if and only if the product of all of its prime factors of the form $4k+3$ is itself a square number.) For example, $490$ and $2450$ can be written as a sum of two squares but $350$ cannot. Try some other examples yourself; for example, $36=4\times 3^2$ so $36$ can be written as a sum of two squares, namely $6^2+0^2$. Try to decide which of the numbers $25$, $37$, $99$ and $245$ can be written as a sum of two squares and when they can, find what the two squares are. For $25$ (and possibly some of the others) there is more than one answer.

Next, let us try to write $n$ as the sum of three squares. It is known that this is possible if and only if $n$ is not of the form $4^m(8k+7)$ (where $m$ can be zero and $4^0=1$); for example, $53=4^0(8\times 6+5)$ can be (try it), but $60=4(8+7)$ cannot (again try it, but not for too long!). What about the numbers $30$, $48$, $77$ and $79$?

The problem of writing $n$ as the sum of three squares is closely connected to the problem of writing $n$ as a sum of three triangular numbers (a whole number $m$ is a triangular number if it is of the form $k(k+1)/2$). For instance, it is known that every number can be written as the sum of three triangular numbers, and this means that every number of the form $8k+3$ can be written as the sum of three squares. To see this suppose that $n=8k+3$ and let

$$k=a(a+1)/2+b(b+1)/2+c(c+1)/2$$

Then $n$ can be written as a sum of three squares because

$$n=8k+3=(2a+1)^2+(2b+1)^2+(2c+1)^2$$

Finally, we may try to write $n$ as the sum of four (or more) squares. In this case the answer is easy to state (but not to prove) for every whole number can be written as the sum of four squares! Of course, we may wish to use $0$ as one of the square numbers, and there are often several ways to do this; for example,$$4=1^1+1^1+1^1+1^1=2^2+0^2+0^2+0^2$$

$$25=5^2+0^2+0^2+0^2=3^2+4^2+0^2+0^2=1^2+2^2+2^2+4^2$$

You should now choose some whole numbers yourself (not too large, though) and try to express each as a sum of four squares.

One of the important steps in considering sums of two squares is the formula $$(a^2+b^2)(c^2+d^2)=(a c+b d)^2+(a d-b c)^2=(a c-b d)^2+(a d+b c)^2$$ which holds for any whole numbers $a$, $b$, $c$, $d$. This formula shows ust hat if $n$ ($=a^2+b^2$) and $m$ ($=c^2+d^2$) are the sum of two squares then so is their product $m n$. To illustrate this, note that $5=2^2+1^2$ and $13=3^2+2^2$ so we can take $a=2$, $b=1$, $c=3$, $d=2$ and so find $65$ ($=5\times 13$) as the sum of two squares in two different ways. A similar formula to this holds for sums of four squares but sadly not for sums of three squares (and it is the lack of such a formula that makes the problem of sums of three squares more difficult to deal with).

It is much harder to see when a number can be written as a sum of cubes (for example $n=a^3+b^3$, or $n=a^3+b^3+c^3$), but it is known that every whole number can be written as a sum of nine cubes (including, if necessary, $0^3$); for example, $$23=2^3+2^3+1^3+1^3+1^3+1^3+1^3+1^3+1^3$$ $$239=4^3+4^3+3^3+3^3+3^3+3^3+1^3+1^3+1^3$$ Curiously, these two numbers ($23$ and $239$) are the only whole numbers that really do need nine cubes; all other whole numbers need only at most eight cubes. See if you can express the numbers $12$, $21$ and $73$ as the sum of at most eight cubes in as many ways as possible.