A locker is toggled once for each factor of its number. It ends open if it is toggled an odd number of times.
Factors come in partner pairs (like 1 × 6 and 2 × 3 for 6), so most numbers have an even number of factors. The exception is when a pair has the same number twice: . The factors of 36 are 1 & 36, 2 & 18, 3 & 12, 4 & 9, and 6 on its own: 9 factors (odd).
So only the square numbers have an odd number of factors, and the open lockers are 1, 4, 9, 16, 25, 36, 49, 64, 81, 100.
The lockers touched exactly twice are those with exactly two factors, the primes; the first five give the code 2-3-5-7-11.
Open lockers: the squares 1, 4, 9, …, 100. Not every number has an even number of factors: squares have an odd number (36 has 9).
