Acertijos de Mileto42 a riddle every day · the solution, the next day Versión en español

2026-11-16 · Logic / Math

The Gym Lockers

In a gym there are 30 lockers numbered 1 to 30, lined up along a corridor. At the start of the day they are all closed.

Thirty people come in, one after another, numbered 1 to 30. Person number k walks down the corridor and changes the state of every locker whose number is a multiple of k: if the locker is closed they open it, and if it is open they close it. So person 1 touches every locker, person 2 touches lockers 2, 4, 6 and so on, person 3 touches lockers 3, 6, 9, and so on. Person 30 touches only locker 30.

After all 30 people have gone through, which lockers are left open?

See solution

Exactly lockers 1, 4, 9, 16 and 25 are left open, that is, the ones bearing a perfect square.

Locker number n is touched once for each divisor of n (person k touches it if and only if k divides n). It starts closed, so it ends up open only if it was touched an odd number of times, that is, if n has an odd number of divisors.

Divisors come in pairs (d, n/d) whose product is n. Each pair contributes two distinct divisors, except when d = n/d, which happens only when n is a perfect square, since then that divisor stands alone. Therefore only perfect squares have an odd number of divisors. Between 1 and 30 the squares are 1, 4, 9, 16 and 25. A quick check: locker 12 has divisors 1, 2, 3, 4, 6 and 12 (six touches), so it ends closed; locker 16 has 1, 2, 4, 8 and 16 (five touches), so it ends open.