Well, for any n where if we are on student number k, then then nth locker changes status (closes or opens) if and only if k divides n.

At the beginning, all the lockers were closed, so if we arrange (k, n/k) as pairs, the net result is that nothing changed from where we started. i.e the nth locker maintains its same status as it had in the beginning, closed. Since the only pairs that could affect the status of the nth locker is when n/k = k, or when k^2 = n. Thus all your 1^2, 2^2, 3^2,4^2, etc... are the only ones who have a status different from when they began as closed. So perfect squares are open. Since 31^2 is the last perfect square less than or equal to 1000, there are 31 lockers opened.