TITLE: The security guard problem
QUESTION [6 upvotes]: There was a security guard in a bank. In front of him were 100 lockers in rows of 10. He thought of something as he saw all the lockers were closed. He started opening all the lockers whose lock numbers were multiples of 1, then closed all lockers whose number was a multiple of 2,and did the same for 3 and so on. If the locker was open, he closed it, if closed, opened it. He went to open multiples of 1 (all),then 2,4,6,8...and then 3,6,9.. And then finally reached 100.
After all the opening and closing,in the end, how many lockers are open and how many closed?

REPLY [10 votes]: Hint: How many divisors does $7$ have? How many divisors does $8$ have? How many divisors does $9$ have? What's special about $9$ and why?
Further Hint: If $a$ divides $n$, then $n = ab$ by definition. For example, $2$ divides $8$ because $8 = 2 \cdot 4$. In this way, divisors arise naturally in pairs.
If the numbers appearing in these pairs are all distinct, then there will be an even number of divisors. For example, the divisors of $8$ (in pairs) are $1$ and $8$ and also $2$ and $4$.
What about when the numbers in the pair aren't distinct? This can only happen if $n = a \cdot a$ for some $a$ (that is, if $n$ is a perfect square). For example, the divisors of $9$ (in pairs) are $1$ and $9$ and also $3$ and $3$. We don't count the $3$ twice, of course, so we get an odd number of divisors.