3 ms·
You 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 l
by bryondowd 10y ago
You 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)).