You have come across an arrangment of 100 doors in a row, all 100 doors are initially closed. You make 100 passes by the doors starting with the first door every time.
Each time you come infront of a door, you toggle it ( i.e. if the door is closed, you open it, if its open, you close it ).
In first pass, you visit every door, in your second pass you visit every 2nd door. [#2, #4, #6……..]
In your third pass, you visit every 3rd door, [#3, #6, #9…….]
And, finally in your 100th visit, you visit only 100th door.
The question is that , Which doors are open in the end?
As I suggest, each time, give it a thought before proceeding to the Solution.
If you notice, A door is toggled in nth walk if n divides door number. For example, the door number 40 is toggled in 1st, 2nd, 4th, 5th, 8th, 10th , 20th and 40th walk.
The door is switched back to initial stage for every pair of divisors. For example 40 is toggled 10 times for 5 pairs (1, 40), (2, 20), (4,10), (5,8) and (1, 45).
If you see closely, It looks like all doors would become closes at the end. But there are door numbers which would become open, for example 16 (1, 2, 8, 4, 16), the pair (4, 4) means only one walk.
Or you can say the numbers which will have odd number of factors. i.e. All other perfect squares like 4, 9, 16, 25 ….
So the answer is 1, 4, 9, 16, 25, 36, 49, 64, 81 and 100.