A puz­zle to begin

Imag­ine a row of lock­ers. Each one is opened or shut once for every fac­tor of its num­ber. At the end, only a few are left stand­ing open. Which ones? The answer depends on a hid­den prop­erty of fac­tors, and that prop­erty picks out the square num­bers. We will start with this puz­zle. Then we will gather what squares look like: their last dig­its, their zeros at the end, whether they are odd or even, and the way they grow by adding odd num­bers.

The locker puz­zle

Sixty lock­ers stand closed, num­bered 11 to 6060. Sixty peo­ple pass by. Per­son 11 opens every locker. Per­son 22 tog­gles every sec­ond locker, which means clos­ing it if it is open and open­ing it if it is closed. Per­son 33 tog­gles every third locker, and so on, until per­son 6060 tog­gles only locker 6060. Which lock­ers are open at the end? Have a guess before you read on.

Take locker 1212. It is touched by per­sons 1,2,3,4,6,121, 2, 3, 4, 6, 12, which are its fac­tors. That is six times, so it ends up closed. A locker ends up open only when it is tog­gled an odd num­ber of times, that is, when its num­ber has an odd num­ber of fac­tors.

Now, fac­tors come in pairs that mul­ti­ply to give the num­ber. For 1212 the pairs are (1,12),(2,6),(3,4)(1, 12), (2, 6), (3, 4). So the count is even, unless one pair uses the same num­ber twice, like (6,6)(6, 6) for 3636. And that hap­pens only when the num­ber is some num­ber mul­ti­plied by itself.

So the open lock­ers are 1,4,9,16,25,36,491, 4, 9, 16, 25, 36, 49. These are the square num­bers up to 6060. Here is a bonus: the lock­ers touched exactly twice, by per­son 11 and by their own num­ber, are the primes.

Sixty lockers numbered 1 to 60 in four rows of fifteen; only lockers 1, 4, 9, 16, 25, 36 and 49, the square numbers, are shaded as open, all others closed.
The lock­ers left open are the square num­bers

Squares

We write n×nn \times n as n2n^2 and read it as "nn squared". The name comes from a square of side nn, which holds n2n^2 small unit squares. The squares of nat­ural num­bers are called per­fect squares: 1,4,9,16,25,…1, 4, 9, 16, 25, \ldots You can square frac­tions, dec­i­mals and neg­a­tive num­bers too: (27)2=449\displaystyle \left(\frac{2}{7}\right)^2 = \frac{4}{49}, (1.5)2=2.25(1.5)^2 = 2.25, (−9)2=81(-9)^2 = 81.

What the last digit tells you

Squar­ing the dig­its 00 to 99 gives last dig­its 0,1,4,9,6,5,6,9,4,10, 1, 4, 9, 6, 5, 6, 9, 4, 1. So a per­fect square always ends in 0,1,4,5,60, 1, 4, 5, 6 or 99. It never ends in 2,3,72, 3, 7 or 88.

Be care­ful, because this test works in one direc­tion only. 20472047 ends in 77, so it can­not be a square. 10461046 ends in 66, but that proves noth­ing. In fact 10461046 is not a square either, since 322=102432^2 = 1024 and 332=108933^2 = 1089.

Here are some handy pat­terns. Num­bers end­ing in 11 or 99 have squares end­ing in 11. Num­bers end­ing in 44 or 66 have squares end­ing in 66. Num­bers end­ing in 55 have squares end­ing in 2525.

Zeros and par­ity

302=90030^2 = 900, 6002=360000600^2 = 360000. Do you see the pat­tern? A num­ber end­ing in kk zeros has a square end­ing in 2k2k zeros. So a square never ends in an odd num­ber of zeros, and that is why 40004000 is not a square.

An even num­ber squared is even, and an odd num­ber squared is odd. In other words, a square is always odd or even just like the num­ber it came from.

Squares grow by odd num­bers

4−1=3,9−4=5,16−9=7,25−16=94 - 1 = 3, \quad 9 - 4 = 5, \quad 16 - 9 = 7, \quad 25 - 16 = 9

Look at the gaps. Squares next to each other dif­fer by odd num­bers that come one after another, because (n+1)2−n2=2n+1(n + 1)^2 - n^2 = 2n + 1. Turn this around and you get a beau­ti­ful fact:

1+3+5+⋯+(2n−1)=n21 + 3 + 5 + \cdots + (2n - 1) = n^2

The pic­ture tells the whole story. An n×nn \times n square grows into an (n+1)×(n+1)(n + 1) \times (n + 1) square when you add an L-shaped bor­der of 2n+12n + 1 unit squares. That draw­ing is a com­plete proof, with­out a sin­gle word.

A 5 by 5 square of unit squares built from one square and L-shaped borders of 3, 5, 7 and 9 squares, each border a different colour, showing 1+3+5+7+9 = 25.
Each L-shaped bor­der adds the next odd num­ber

Exam­ple 1. Given 432=184943^2 = 1849, find 44244^2. Just add the 4444th odd num­ber, which is 2×44−1=872 \times 44 - 1 = 87. So 1849+87=19361849 + 87 = 1936.

Exam­ple 2. Is 5252 a square? Keep sub­tract­ing 1,3,5,…1, 3, 5, \ldots in turn: 52→51→48→43→36→27→16→3→−1252 \to 51 \to 48 \to 43 \to 36 \to 27 \to 16 \to 3 \to -12. It never lands on 00, so the answer is no. Now try 4949: 49→48→45→40→33→24→13→049 \to 48 \to 45 \to 40 \to 33 \to 24 \to 13 \to 0. It reaches zero after seven sub­trac­tions, so 49=7249 = 7^2.

Between two squares

Between n2n^2 and (n+1)2(n + 1)^2 lie 2n2n num­bers that are not squares. For exam­ple, between 82=648^2 = 64 and 92=819^2 = 81 there are six­teen num­bers, and between 30230^2 and 31231^2 there are sixty.

This means squares get rarer as you go up. There are ten of them up to 100100, but only four between 101101 and 200200 (121,144,169,196121, 144, 169, 196), and three between 201201 and 300300. The largest square below 10001000 is 312=96131^2 = 961.

Squares and tri­an­gu­lar num­bers

Tri­an­gu­lar num­bers count dots in a tri­an­gle: 1,3,6,10,15,21,…1, 3, 6, 10, 15, 21, \ldots Add any two that sit next to each other, and you get a square: 3+6=93 + 6 = 9, 10+15=2510 + 15 = 25, 21+28=4921 + 28 = 49. The pic­ture shows why: two stair­cases fit together to make a square.

A 5 by 5 square of dots split along a staircase into a triangle of 10 dots and a triangle of 15 dots, showing that 10 + 15 = 25, a square number.
Two stair­cases of 10 and 15 dots fit into a 5 by 5 square

Prac­tice

  1. Which of these can­not be per­fect squares, judged by their last digit alone? 32533253, 17281728, 47614761, 90079007, 21162116, 50005000.
  2. Which of 57257^2, 63263^2, 84284^2, 96296^2 end in 66?
  3. Given 712=504171^2 = 5041, find 72272^2 by adding the right odd num­ber.
  4. Given 1152=13225115^2 = 13225, write 1162116^2 as 13225+_13225 + \_.
  5. Use repeated sub­trac­tion of odd num­bers to decide whether 6464 and 7575 are squares.
  6. How many num­bers lie between 23223^2 and 24224^2? Between 1992199^2 and 2002200^2?
  7. How many per­fect squares lie between 301301 and 400400? Between 901901 and 10001000?
  8. The 66th and 77th tri­an­gu­lar num­bers are 2121 and 2828; their sum is which square? What about the 99th and 1010th, 4545 and 5555?
  9. In a row of 4040 lock­ers with the same rule, which stay open, and which are touched exactly twice?

Answers

Show answers
  1. 32533253 (ends in 33), 17281728 (88), 90079007 (77). The oth­ers pass the test but only 4761=6924761 = 69^2 and 2116=4622116 = 46^2 are squares; 50005000 ends in three zeros, so it is not.
  2. 84284^2 and 96296^2 (last dig­its 44 and 66).
  3. 7272nd odd num­ber is 143143: 5041+143=51845041 + 143 = 5184.
  4. 13225+23113225 + 231, since 2×116−1=2312 \times 116 - 1 = 231; 1162=13456116^2 = 13456.
  5. 64→63→60→55→48→39→28→15→064 \to 63 \to 60 \to 55 \to 48 \to 39 \to 28 \to 15 \to 0: eight steps, 64=8264 = 8^2. 75→74→71→66→59→50→39→26→11→−675 \to 74 \to 71 \to 66 \to 59 \to 50 \to 39 \to 26 \to 11 \to -6: not a square.
  6. 2×23=462 \times 23 = 46; 2×199=3982 \times 199 = 398.
  7. 324,361324, 361: two. 961961: one.
  8. 21+28=49=7221 + 28 = 49 = 7^2; 45+55=100=10245 + 55 = 100 = 10^2.
  9. Open: 1,4,9,16,25,361, 4, 9, 16, 25, 36. Touched twice: 2,3,5,7,11,13,17,19,23,29,31,372, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37.