Created
October 24, 2015 18:58
-
-
Save thetyrelcorporation/4587a7d1b34d1b569eb3 to your computer and use it in GitHub Desktop.
My first math lib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate num; | |
use self::num::traits::{Num, Zero, One, Signed, Unsigned, Bounded, Saturating, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv, PrimInt, Float, ToPrimitive, FromPrimitive, NumCast} | |
pub fn number_of_factors<T: Num + Zero + One + Signed + Unsigned + Bounded + Saturating + CheckedAdd + CheckedSub + CheckedMul + CheckedDiv + PrimInt + Float + ToPrimitive + FromP | |
let one = 1 as T; | |
let zero = 0 as T; | |
let mut factor_count: T = one; | |
let mut limit = n; | |
let mut i: T = one; | |
while i < limit { | |
if n % i == zero { | |
limit = n / i; | |
if limit != i { | |
factor_count = factor_count + one; | |
} | |
factor_count = factor_count + one; | |
} | |
i = i + one; | |
} | |
factor_count | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment