Wednesday, March 5, 2025

Opening and closing treasure chests.

Suppose there are 500 treasure chests, each labeled 1 to 500. There are also 500 pirates. Initially all 500 treasure chests are closed. Then the first pirate opens all the treasure chests. Next, the second pirate opens every other treasure chest, labeled 2, 4, 6, and so on. Then the third pirate changes the state of the treasure chest from closed to open, or open to close on chests labeled 3, 6, 9, and so on. In general, the `n`th pirate changes the state of the chests that has label a multiple of `n`. 

After the 500th pirate, how many chests are open?

No comments: