A jailer, carrying out the terms of a partial amnesty, unlocked every cell in the prison row. Next, he locked every second cell. Then he turned the key in every third cell, locking those cells which were open and opening those cells which were locked. He continued this way, on the nth trip turning the key in every nth cell. Those prisoners whose cells eventually remained open were allowed to go free. Who were the lucky ones?