Home > Riddles > The switches and the million of light bulbs

The switches and the million of light bulbs

A million switches seem to invite us to imagine an avalanche of changes. The output appears by looking at a single light bulb and wondering how many times it changes state.

In a hallway there are a million light bulbs, numbered from 1 to 1,000,000. At first, they are all turned off.

A person walks down the hallway many times. In the first pass the state of all the bulbs changes.

In the second, the state of the even bulbs changes. In the third, the state of the bulbs numbered with multiples of 3 changes.

And so on: in the pass number $k$, the state of all the bulbs whose number is a multiple of $k$ changes. After completing the 1,000,000th pass, how many light bulbs remain lit?

Hints

Show hints
  1. Do not reason bulb by bulb; each pass follows a regular divisor pattern.
  2. Count how many divisors each bulb index has.
  3. Only bulbs toggled an odd number of times remain on.
  4. That happens exactly for perfect squares.

Solution

Show full solution

Answer: Exactly 1000 bulbs remain lit: those that occupy perfect square positions. Explanation: The light bulb $n$ changes state once for each positive divisor of $n$, because it is activated by every person whose number divides $n$. Typically divisors come in pairs: if $d$ divides $n$, it also divides $n/d$. That produces an even number of changes and the bulb ends up going out. The only exception is perfect squares. For example, in 36 the divisor 6 appears paired with itself, and therefore the total number of divisors is odd. Bulbs with an odd number of changes stay on. Between 1 and 1,000,000 there are exactly 1000 perfect squares:

$$ 1^2,2^2,\dots,1000^2. $$

Related riddles

Keep practicing

If you enjoyed this one, try more pure-logic riddles, explore this theme, browse the full archive, or read the riddle-solving guide.

← Previous: Sum and product · Next: The three prisoners and the red hats →