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)

  Submitted by levik    
Rating: 3.5000 (6 votes)
Solution: (Hide)
Since we "toggle" the doors, we can realize that the only doors that are open at the end of the exercise are the ones that are toggled an odd number of times. We also know that a door is toggled once for each divisor that it has.

But divisors come in pairs. By definition, if N is divisible by M, there is also some other number K = N/M which N will be divisible by.

The only way around this is when K = M, which means that N = M^2. When we are dealind with doors whose number is a perfect square, they will be toggled only once for the pair of divisors that is a square of.

(So 4 can be broken into 1*4 and 2*2, meaning it will be open on the first, closed on the second and re-opened on the fourth passes.)

Since there are 10 perfect squares between 1 and 100, that's how many doors will stay open.

Comments: ( You must be logged in to post comments.)
  Subject Author Date
SolutionMore Detailed SolutionK Sengupta2008-06-05 03:27:46
answerK Sengupta2007-03-08 12:27:47
solutionDetti2004-10-07 11:10:01
Questionre: The solution...Gamer2003-07-03 14:33:20
SolutionThe solution...Paul Pereira2003-05-07 03:10:55
re: hmmlevik2002-08-27 09:27:37
hmmMel2002-08-27 03:56:54
Opening Doorsbaja2002-05-02 09:58:22
typos in last commenttheBal2002-05-01 18:04:48
basic number theorytheBal2002-05-01 18:02:46
Correction.Dominic2002-05-01 10:54:00
Educated GuessDominic2002-05-01 10:43:07
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (6)
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