One thousand students stand in line outside a school, each numbered 1 to 1000. In the school are one thousand closed lockers, each numbered 1 to 1000. One by one, the students go into the school and “change the state” of the lockers. That is, if a locker is open, they close it; if it is closed, they open it.
Here are the rules:
The first student goes in and changes the state of each locker. The second student goes in and changes the state of every other locker. The third student goes in and changes the state of every third locker. The fourth student goes in and changes the state of every fourth locker. And so on. Eventually, the thousandth student goes in and changes the state of the thousandth locker.
After all one thousand students have completed their task, how many lockers are open?