april's answer

The number of times t that the key was turned in the qth cell is equal to the number of divisors of q. Thus if q=p1a1.p2a2...pkak where the pi's are distinct primes, then t=(ai+1)(a2+1)...(ak+1). Now if any ai is odd, t is even and the corresponding cell eventually remained locked. If all the ai are even, q is a square number, t is odd and the lucky occupants of the "square" cell found that their cells eventually remained open.