Rust Count Factors
fn count_factors(n: i64) -> i64 {
let mut count = 0;
let mut i = 1i64;
while i * i < n {
if n % i == 0 {
count += 2;
}
i += 1;
}
if i * i == n {
count += 1;
}
count
}
This checks divisors in pairs up to the square root, which keeps the work much smaller than testing every number.