Light-Bulb Switching Problems
A bulb ends up on or off depending on how many times it's toggled, and the toggle count is a divisor-counting question in disguise — which is why perfect squares are the odd ones out.
Prerequisites: How to Attack a Brainteaser
This puzzle looks like it needs simulation — 100 bulbs, 100 passes, track every flip — but the toggle count for each bulb reduces to a single number-theoretic fact once you stop thinking about passes and start thinking about divisors.
The puzzle
100 light bulbs, numbered 1 to 100, all start off. There are 100 people. Person walks along the row and toggles the switch on every bulb whose number is a multiple of (so person 1 toggles every bulb, person 2 toggles every even-numbered bulb, and so on up to person 100, who toggles only bulb 100). After all 100 people have gone, which bulbs are on?
Reframe the question. Bulb starts off, and its final state depends only on how many times it gets toggled — an odd number of toggles leaves it on, an even number leaves it off (it started off, and each toggle flips the state). Person toggles bulb exactly when divides . So the number of times bulb gets toggled equals the number of positive divisors of .
When is the divisor count odd? Divisors of normally pair up: if divides , so does , and these are two different numbers () unless , i.e. . So divisors come in pairs except when is a perfect square, in which case pairs with itself and contributes only one divisor to the count instead of two.
The answer. Bulb ends up on exactly when has an odd number of divisors, which happens exactly when is a perfect square. Among 1 to 100, that's — the 10 perfect squares end up lit, and the other 90 bulbs are off.
"Toggled an odd number of times" is a divisor-counting question, and divisor counts are odd only for perfect squares — because divisors pair up as except when . Any puzzle phrased as "person acts on multiples of " reduces to this same pairing argument.
Don't simulate 100 people toggling 100 bulbs by hand. Reframe "how many times is bulb touched" as "how many divisors does have," and the parity argument answers the whole puzzle in three lines.
The reframing habit — trading a simulation for a closed-form count over divisors — is the same move behind sieve-based algorithms (like the Sieve of Eratosthenes) that avoid checking every number against every other number individually.
Related concepts
Practice in interviews
Further reading
- Engel, Problem-Solving Strategies (ch. 1)