There are 100 doors in a row, all doors are initially closed. A person walks through all doors multiple times and toggle (if open then close, if close then open) them in following way:

In first walk, the person toggles every door

In second walk, the person toggles every second door, i.e., 2^{nd}, 4^{th}, 6^{th}, 8^{th}, …

In third walk, the person toggles every third door, i.e. 3^{rd}, 6^{th}, 9^{th}, …

………

……….

In 100^{th} walk, the person toggles 100^{th} door.

**Which doors are open in the end?**

**Solution:**

A door is toggled in i^{th} walk if i divides door number. For example the door number 45 is toggled in 1^{st}, 3^{rd}, 5^{th}, 9^{th} and 15^{th} walk.

The door is switched back to initial stage for every pair of divisors. For example 45 is toggled 6 times for 3 pairs (5, 9), (15, 3) and (1, 45).

It looks like all doors would become closes at the end. But there are door numbers which would become open, for example 16, the pair (4, 4) means only one walk. Similarly all other perfect squares like 4, 9, ….

So the answer is 1, 4, 9, 16, 25, 36, 49, 64, 81 and 100.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Puzzle | Thief, Treasure and 2 Doors
- Puzzle 81 | 100 people in a circle with gun puzzle
- Puzzle 39 | (100 coins puzzle)
- Puzzle 13 | (100 Prisoners with Red/Black Hats)
- Puzzle 20 | (5 Pirates and 100 Gold Coins)
- Puzzle | Set 35 (2 Eggs and 100 Floors)
- Puzzle | 100 Cows And Milk
- Puzzle | 100 wrong statements
- Puzzle 15 | (Camel and Banana Puzzle)
- Puzzle 24 | (10 Coins Puzzle)
- Puzzle 27 | (Hourglasses Puzzle)
- Puzzle 28 | (Newspaper Puzzle)
- Puzzle 29 | (Car Wheel Puzzle)
- Puzzle 31 | (Minimum cut Puzzle)
- Puzzle 33 | ( Rs 500 Note Puzzle )
- Puzzle 34 | (Prisoner and Policeman Puzzle)
- Puzzle 36 | (Matchstick Puzzle)
- Puzzle 38 | (Tic Tac Toe Puzzle)
- Puzzle 51| Cheryl’s Birthday Puzzle and Solution
- Puzzle 85 | Chain Link Puzzle