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

2026-10-27 · Logic / Math

The Hallway Lamps

A long hallway has 40 lamps numbered 1 to 40, all of them off at the start. Then 40 people, also numbered 1 to 40, walk down the hallway one after another, in order.

Person number k flips the state (off becomes on, on becomes off) of every lamp whose number is a multiple of k. So person 1 touches every lamp, person 2 touches lamps 2, 4, 6, and so on, person 3 touches lamps 3, 6, 9, and so on, all the way to person 40, who touches only lamp 40.

After the last person has passed, which lamps are left on?

See solution

Exactly lamps 1, 4, 9, 16, 25 and 36 are left on, that is, the ones bearing a perfect square.

Lamp number n is touched once for each divisor of n, so it ends up on if and only if n has an odd number of divisors (it starts off and every touch flips it). Divisors come in pairs: if d divides n, so does n/d, and the two are different unless d × d = n. So the number of divisors is odd only when n is a perfect square, since then one divisor is left without a partner. The perfect squares between 1 and 40 are 1, 4, 9, 16, 25 and 36.