All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > General
Opening doors (Posted on 2002-05-01) Difficulty: 3 of 5
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)

See The Solution Submitted by levik    
Rating: 3.5000 (6 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
basic number theory | Comment 3 of 12 |
we can see that a door is open if and only if it had been toggled an odd number of times, which happens if and only if the door number have odd number of factor (since each factor contribute one toggle). Now for each number n which have factor d, then n/d is also a divisor. so for 'almost' all number we can pair the factors as (d,n/d), yielding odd number of factors. the only exception, of course if when d=n/d so that there'll be no pair, and this is possible if and only if n=d^2, i.e n is a perfect square. so, the answer is the number of perfect squares <= 100, namely 10.
  Posted by theBal on 2002-05-01 18:02:46
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (12)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information