The Locker Problem

Imagine you are at a school that still has student lockers. There are 1000 lockers, all shut and unlocked, and 1000 students.

Here's the problem:

1. Suppose the first student goes along the row and opens every locker

2. The second student then goes along and shuts every other locker beginning with number 2

3. The third student changes the state of every third locker beginning with number 3. (If the locker is open the student shuts it, and if the locker is closed the student opens it.)

4. The fourth student changes the state of every fourth locker beginning with number 4. Imagine that this continues until the thousand lockers have followed the pattern with the thousand lockers.

At the end, which lockers will be open and which will be closed? Why?