Reply to comment

A prisoner n is visited by an officer d, if d divides n. For instance, prisoner 63 is visited by officer 7, but not by officer 8. So we have to determine the divisors of the prisoner numbers. For example, prisoner 16 is visited by officer 1, 2, 4, 8 and 16. 1 opens, 2 closes, 4 opens, 8 closes and finally, 16 opens the door for the lucky prisoner. On the other hand, prisoner 63 can not escape, because he/she has an even number of divisors: 1,3,7,9,21 and 63 and the last one closes the door. The prisoners who are allowed to escape have an odd number of divisors. Here they are (the number of divisors in brackets): 1(1), 4(3), 9(3), 16(5), 25(3), 36(9), 49(3), 64(7), 81(5) and 100(9)