Fortnightly maths prize for 7 July

Nearly 100 years ago, the great mathematician Srinivasa Ramanujan was ill in hospital. His friend G H Hardy, professor of maths at Cambridge, went to visit him.

Casting around for light conversation, and knowing that Ramanujan was specially interested in number theory, Hardy told Ramanujan that the taxi he’d come in had the number 1729. But, thought Hardy, that wasn’t a very interesting number.

Little did he know. The desperately ill man’s face lit up. “No, no”, he said. “It is a very interesting number; it is the smallest number which can be written as the sum of two cubes in two different ways.”

So it is. 13+123=103+93=1729.

Your prize question is this: You are ill (just a bug, not as ill as Ramanujan, but ill). A friend comes to visit. She or he tells you the number of the bus they’ve come by.

You say: “Aha. That’s the smallest number which can be written as the sum of squares in two different ways”.

You mean like 221 can be written as a sum of squares in two different ways, 102+112 or 142+52, and 169 can be written as 52+122 or 132+02, though those aren’t the smallest numbers that can be written that way.

Question: (1) What was the number of the bus?

(2) What was the number of the bus if it was the smallest number which can be written as the sum of non-zero squares?

To help you, both answers are two-digit numbers. You can find it just by trying out numbers one after the other, or by heavier maths.

Mugisha Uwiragiye won the prize. He used the spreadsheet method (way 1 below).

(2) 50.

You know the answer 25 because you know 3, 4, 5 is the smallest right-angled triangle with whole-number sides, so 25 is the smallest square which is the sum of two squares. 32+42=52+02.

The first way to find the answer 50 is to make a spreadsheet with rows labelled 1 to 9 and columns labelled 1 to 9, and each cell containing the square of the row number and the column number. Then just look.

Second way: use difference of squares.

Firstly, see

a2+b2=c2+d2

means a2−c2=d2−b2

thus (a+c)(a−c)=(d+b)(d−b)

so as soon as we find a number which has two different factorisations, in both of which the factors differ by an even amount (i.e. both factors odd, or both factors even: so it must be an odd number, or a number divisible by 8), then from it we can calculate a number which is a sum-of-two-squares in two different ways.

9 = 1×9 = 3×3 gives us a+c=9, a−c=1, d+b=3, d−b=3, so a=5, c=4, b=0, d=3. 42+32=52+02=25

15 = 3×5 = 1×15 gives us 42+72=82+12=65

At this point you might think that the smallest number which is the sum of two non-zero squares in two different ways is 65. But no!

16 = 2×8 = 4×4 gives us 32+42=52+02=25 again

21 = 3×7 = 1×21 gives us 112+22=102+52=125

but 24 = 4×6 = 2×12 gives us 72+12=52+52=50

If the number M being factorised = a2−c2=d2−b2, then both a2 and d2 are greater than M, so the sum-of-squares number produced by calculating from the two different factorisations of M must be bigger than M.

To be sure that 50 is the smallest, we need only check the other two-different-factorisations numbers between 24 and 49. A quick scan of them shows that for each of them one of the numbers in one of the factorisations is bigger than 2√50, so we’re done.

Third way: go through the numbers 1, 2, 3, 4, …. one by one until you find the first one which is the sum of two non-zero squares in two different ways.

Fourth way:

You can limit the numbers you have to try out by noticing that, just as all numbers are either odd or even, all numbers are of one of four types:

00 – divisible by 4
01 – remainder 1 when divided by 4
10 – remainder 2 when divided by 4
11 – remainder 3 when divided by 4

All square numbers are of type 00 or 01

Therefore all sums-of-two-squares are of type 00, 01, or 10

So you don’t have to check numbers of type 11.

A further argument shows you have to check numbers N of type 10 only if ½N is an exact square of a number of type 01. That means the only two-digit numbers of type 10 you have to check are 2 and 50.

A sum-of-squares N of type 10 must be made up as

N=(4m+1)2+(4n+1)2 – in which case (2m+2n+1)2+(2m−2n)2=½N

or N=(4m+3)2+(4n+3)2 – in which case (2m+2n+3)2+(2m−2n)2=½N

or N=(4m+3)2+(4n+1)2 – in which case (2m+2n+2)2+(2m−2n+1)2=½N

So, for each way in which N is a sum-of-squares, there is a corresponding way in which ½N is a sum-of-squares. If N is a sum-of-squares in two ways, so is ½N unless (2m−2n)=0. In that case, m=n and ½N=(4n+1)2. Thus there is only a possibility of N being the smallest number which is a sum of two non-zero squares in two ways if ½N is the exact square of a number of type 01.

So it’s enough to check only a few more than half the numbers between 1 and 99, namely 1, 2, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29, 32, 33, 36, 37, 40, 41, 44, 45, 48, 49, 50, 52, 53, 56, 57, 60, 61, 64, 65, 68, 69, 72, 73, 76, 77, 80, 81, 84, 85, 88, 89, 92, 93, 96, 97.

If you look up the general rules for numbers being sums-of-two-squares, you also know you need check only the numbers whose prime factors are 2 and odd primes of type 01.

Thus you need check only 5, 8, 13, 16, 20, 25, 29, 32, 37, 40, 41, 50, 52, 53, 57, 61, 64, 65, 68, 73, 80, 85, 89, 92, 97.

You’ll get the answer, 50, as the 12th number you check.

A fifth way, with a bit more maths: if you multiply together any two different numbers which are sums-of-two-squares-different-from-each other (e.g. 5=22+12, but not 8=22+22), then the answer is a sum of squares in two different ways

(a2+b2)(c2+d2)
=a2c2+b2d2+a2d2+b2c2
=a2c2+2acbd+b2d2+a2d2−2acbd+b2c2