There are $50$ persons in a row of locked cells. With return of the king from the Crusade, a partial amnesty is declared and it work like this. When the prisoners are stills asleep, the jailer walk past the cells $50$ times, each time walking from left to right. On the first past, the turns the lock in every cell (so that every cell is open ). On the second pass he turns the lock on every second cell (meaning that these cells are now locked again ) . on the third pass, he turns the lock on every third cell , and so on . In general, on the $k th$ pass, he turns the lock on every $k th$ cell. The question is : which cells are unlocked at the end of the process so that the prisoner is free to go?
-
What are your thoughts? – The Chaz 2.0 May 05 '17 at 03:14
-
I'm just wondering how many times I've seen this same question on this site in various forms – The Dead Legend May 05 '17 at 03:14
1 Answers
Answer, simply is that the perfect square doors will be open at the end. ie. $1,4,9,16,25,36,49$
You can figure out that for any given cell, say door #42, you will visit it for every divisor it has. so $42$ has 1 & 42, 2 & 21, 3 & 14, 6 & 7. so on pass $1$ I will open the cell, pass 2 i will close it, pass 3 open, pass 6 close, pass 7 open, pass 14 close, pass 21 open, pass 42 close. for every pair of divisors the door will just end up back in its initial state. so you might think that every cell will end up closed?
well what about door #9. 9 has the divisors 1 & 9, 3 & 3. but 3 is repeated because 9 is a perfect square, so you will only visit door #9, on pass 1, 3, and 9… leaving it open at the end. only perfect square doors will be open at the end.
- 4,727