In a (extremely long) corridor in a hotel there are $1000$ doors each with a single person living in the room behind. The hotel manager suddenly receives a bill and must kick out most of guests to save money. He has the $1000$ inhabitants line up in order of there room number ($1$-$1000$).

He tells the inhabitant of Room 1 to go and open every door. He then tells the inhabitant of Room 2 to go and open every second door if closed and shut it if its open. He then tells the inhabitant of Room 3 to open every third door if its closed and shut it if its open. And this goes on till the 1000th inhabitant.

He then tells the inhabitants that the people with their door open can stay.

How many can stay and which rooms have their door open?


1 Answer 1


Everyone whose room number is a square can stay. This would be room numbers: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, and 961, for a total of 31 people.

P.S. I have no idea how exactly the markdown works with the spoilers, so excuse it being illegible.


#1 opens every door. #2 then closes every even door, leaving 1 open and 2 closed. The process continues of opening and closing doors, and the square doors remain open because they have 1 factor which when multiplied by itself gives the number, but it is only counted once, leaving the door open.

  • $\begingroup$ Correct, but can you explain why in a bit more detail? $\endgroup$ Apr 23, 2016 at 11:19
  • $\begingroup$ @beastlyGerbil Take any number n and list it's factors. Every factor below the square root of n will have a corresponding factor above the square root, resulting in an even number of factors. The only exceptions are the square numbers, which have an odd number of factors because the square root is only counted once. since each factor is a 'flip' of the door, only an odd number of flips leaves the door open $\endgroup$ Apr 23, 2016 at 11:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.