Learn / Library / Brainteasers
Half open to begin with
lockers are numbered to . At the start every even-numbered locker is open and every odd-numbered locker is closed. Then for each from to , student toggles every locker whose number is a multiple of , opening it if closed and closing it if open. How many lockers are open at the end?
Checking an answer needs JavaScript. The hint and the solution open without it.
Hint
Combine the starting state with the parity of the number of divisors.
Solution
- Locker changes state once per divisor of , so only the perfect squares change state an odd number of times.
- So a non-square keeps its starting state and a square ends in the opposite state.
- Up to there are squares, since and ; of these, are even and are odd.
- Open at the end are the even non-squares, of them, and the odd squares, of them.
- So lockers are open.
Answer: