learnimate
Film · 8:35

Perfect Squares: The 100 Lockers Puzzle

NCERT Class 8 Maths · Ganita Prakash · A Square and a Cube · Section 1.1

The idea

The puzzle. Picture a corridor of 100 closed lockers and 100 students. Student 1 opens all of them. Student 2 visits lockers 2, 4, 6 and so on, closing any that are open and opening any that are shut. Student 3 does the same with every third locker, and the pattern continues until student 100 touches only the last locker. When the corridor is quiet again, just ten lockers stand open: 1, 4, 9, 16, 25, 36, 49, 64, 81 and 100. All ten are perfect squares, and no other number makes the list.

A grid of 100 lockers with only lockers 1, 4, 9, 16, 25, 36, 49, 64, 81 and 100 open, listed beside the grid
After all 100 students pass, only the squares are open.

Counting flips. Slow down and follow one locker at a time. Locker 6 is touched by students 1, 2, 3 and 6, four flips in total, so it goes open, shut, open, shut. Locker 9 is touched by students 1, 3 and 9, and three flips leave it open. Since every locker begins shut, an even number of flips returns it to shut and an odd number leaves it open. A prime-numbered locker such as 7 gets exactly two visits, so every prime locker finishes closed.

Flips are divisors. Student reaches locker only when divides . So locker 12 is flipped by 1, 2, 3, 4, 6 and 12, six times, and stays closed; students 7 to 11 never stop there. The puzzle has turned into a plain question about numbers: which numbers up to 100 have an odd count of divisors? Locker 16 has five (1, 2, 4, 8, 16), so it ends open.

Divisors come in pairs. Arrange 12 dots as rectangles: 1 by 12, 2 by 6, 3 by 4. Each rectangle hands you two divisors at once, its width and its height, so the divisors of 12 match up into three pairs. Now try 36: 1 and 36, 2 and 18, 3 and 12, 4 and 9, and finally 6 and 6. That last rectangle is a square, and 6 is its own partner, so it is counted only once. Four pairs plus a single 6 gives nine divisors, an odd number.

The divisors of 12 in a row, joined by arcs into the pairs 1 and 12, 2 and 6, 3 and 4
The divisors of 12 form three pairs: six in all.

Why only squares stay open. A divisor can partner itself only when the number is something multiplied by itself. So squares, and only squares, have an odd number of divisors. With 1,000 lockers the open ones run from to , because fits but does not: 31 lockers. With 10,000 lockers, exactly 100 stay open.

Quick tests. A square always ends in 0, 1, 4, 5, 6 or 9, so anything ending in 2, 3, 7 or 8 is out at a glance. That test only rules numbers out, though. Zeros help too: a square has an even number of zeros at the end, which is why 1,000 fails. The test that never fails is prime factorisation, where every prime must appear an even number of times. passes; has a spare 2 and does not.

Between squares. From 25 to 36 there are ten numbers that are not squares, and ten is twice 5. In general, between and sit non-squares, because the jump from one square to the next is the odd number , the L-shaped border that grows one square into the next.

A 5 by 5 square of dots wrapped by an L of 11 dots to make a 6 by 6 square
An L of 11 dots turns 25 into 36.

Key formulas

teal what we're studying · yellow what's changing · coral a common slip

Common mistake

Trusting the last-digit test in both directions. A square never ends in 2, 3, 7 or 8, so a number like 2,437 is ruled out at once. But is wrong: 2,431 ends in 1, yet , so it is not a square.

The last digit can only rule a number out. To prove a number is a square, use its prime factorisation and check that every prime comes in pairs.

Exam lens

Find the smallest number by which 72 must be multiplied to get a perfect square.