Imagine a row of 100 closed doors. Now, make 100 passes along the row, and at each pass "toggle" the doors whose number is divisible by the number of the pass. (
By "toggle", we mean to open a closed door, or close an opened one.)
For example, on the first pass, we will toggle all the doors, on the second, we will toggle only the even-numbered doors, on the third - only doors whose number is divisible by three, and so on.
At the end of the 100 passes, how many doors will be left open?
(from techInterview.org)
(In reply to
hmm by Mel)
Not so. For example 3 is a prime number. Door number 3 will be open on the first pass, and closed on the third, never to be touched again. Thus, the door will stay closed.
|
Posted by levik
on 2002-08-27 09:27:37 |