There are two better ways of doing this. One way involves only solving up to the sqrt of the value; you will also have a special case to look out for when a perfect square appears. The other way, and more efficient way, would be to look at a table of prime factors; add the exponents together to get the amount of factors.