5 ms·
The first door will only be flipped once, by the first person. The fourth door will be flipped by the first, second, and fourth people (three times). The ninth
by shaldengeki 10y ago
The first door will only be flipped once, by the first person.
The fourth door will be flipped by the first, second, and fourth people (three times).
The ninth door will be flipped by the first, third, and ninth people (three times).
The sixteenth door will be flipped by the first, second, fourth, eighth, and sixteenth people (five times).
The twenty-fifth door will be flipped by the first, fifth, and twenty-fifth people (three times).
The thirty-sixth door will be flipped by the first, second, third, fourth, sixth, ninth, twelfth, eighteenth, and thirty-sixth people (nine times).
It should be clear here that the number of times the nth door is flipped is the number of unique divisors that n has.
For any non-perfect square n, for any divisor p, n/p = q is another divisor not equal to p. So non-perfect square numbers have an even number of divisors.
Perfect square numbers are the only numbers that have an odd number of divisors, which in this game corresponds to being flipped an odd number of times.
- bryondowd 10y agoYou could take this a step further. For any number of lockers/kids, if you start at 1 and square each number until you get a number that exceeds the number of lockers/kids, you've found all of your perfect squares in that range. Which, of course, is the square root of your original number, rounded down to the nearest whole number. So, for any number of lockers/kids, n, the number of open doors is simply floor(sqrt(n)).