There are N men in cells numbered 1 2 3V in a linear cell bl
There are N men in cells numbered 1, 2, 3,...,.V in a linear cell block: 1 2 3 4 5... N The warden and the inmates agree to perform the following N-ilay experiment: On the first day of the experiment, the warden unlocks everybody\'s cell door. On the second day, the warden locks the cell door of every second inmate (i.e., cell numbers 2, 4, 6, 8,...). On the third day, the warden turns the key in the cell door of every third inmate (i.e., cell numbers 3, 6, 9,...). For instance, the man in cell number 3 has his cell locked on the third day, whereas the man in cell number 6 has his cell unlocked on the third day. In general, on the k^th day, for every value of k such that 1 lessthanorequalto k lessthanorequalto N, the warden turns the key in every cell (i.e., cell numbers k, 2k, 3k,...). The gentlemen\'s agreement is: Nobody will attempt to escape during the course of the experiment, and An inmate gets out of jail at the end of the N-day experiment if and only if his cell door is unlocked at that time. Your problem is to describe precisely who goes free at the end of the N-day experiment.
Solution
This is a very famous puzzle problem
In the first attempt, he will unlock all the doors and in the second attempt, he will open the even number doors
This mean first door will be remain opened at the end of nth day
Similarly, he will open 4th door at 1st day, close it at 2nd day and then again open it at 3rd day, so the 4th door will also be opened at the end of nth day
Hence all the doors with perfect square numbers will be opened and remaining doors will be closed, so all the doors which are perfect square and less than equal to N will be opened
