Haskell Count Factors
countFactors :: Int -> Int
countFactors n = finalize (loop 1 0)
  where
    loop i count
      | i * i < n = loop (i + 1) (if n `mod` i == 0 then count + 2 else count)
      | otherwise = (i, count)

    finalize (i, count) = if i * i == n then count + 1 else count

This checks divisors in pairs up to the square root, which keeps the work much smaller than testing every number.