Let's try this with just 9 lockers......I think you might see the answer
After the second student goes through......
O C O C O C O C O
After the third student goes through
O C C C O O O C C
After the 4th
O C C O O O O O C
After the 5th
O C C O C O O O C
After the 6th
O C C O C C O O C
After the 7th
O C C O C C C O C
After e 8th
O C C O C C C C C
After the 9th
O C C O C C C C O
Notice that, after the 9th person, lockers 1, 4 and 9 are open........what are those numbers???
Perfect squares !!!
And the number of perfect squares from 1 - 1000 = 31
So......31 lockers will be open at the end.......and the rest closed
The reason for this is that all non-squared integers have an even number of proper and improper divisors ......thus......they will have some number of O-C pairings and have the state of "C" at the end of the process....consider the number 6......it is open on the first pass.....closed on the second, open on the third and closed on the sixth....thus, it has the states O-C and O-C
Squared numbers, on the other hand, always have an odd number of proper and improper divisors......they will have the state of "O" at the end.......consider 9.....
It is opened on the first pass, closed on the third and opened again on the ninth....and it is never touched after that !!!!!
