extern crate num; use num::{Num, One, Zero}; pub fn number_of_factors(target: T) -> T where T: Num + Ord + Copy { let mut factor_count: T = Zero::zero();; let mut limit: T = target; let mut i: T = One::one(); while i < limit { if target % i == Zero::zero() { limit = target / i; if limit != i { factor_count = factor_count + One::one(); } factor_count = factor_count + One::one(); } i = i + One::one(); } factor_count } #[test] fn test1() { assert_eq!(number_of_factors(9u64), 3u64); assert_eq!(number_of_factors(12i32), 6i32); }