Count the square root once
transcript
How many divisors does thirty-six have? Your loop says ten. The answer is nine. The mistake hides in one perfect square.
Ten to the twelve is too many to loop. Try sizes only up to the square root. Each hit gives a divisor and its partner. So the loop is short, but it has one edge.
One pairs with thirty-six. Two pairs with eighteen. And six pairs with six. It is the same number. Six is its own partner, so it counts once.
Adding two for every hit counts six twice. Check whether size squared equals n. If it does, add one, not two. Then thirty-six gives nine, as it should.
The wrong loop is right for most numbers. It fails only on perfect squares. So the samples may never show it. Always test a perfect square, such as thirty-six or forty-nine.
Test a perfect square. Thirty-six is a good one. Full breakdown in the lecture.