diff --git a/src/math.rs b/src/math.rs index 1a0fb80..11c08c5 100644 --- a/src/math.rs +++ b/src/math.rs @@ -49,6 +49,14 @@ pub fn factorial(n: u64) -> u64 { result } +pub fn binomial(n: u64, k: u64) -> u64 { + if k > n { + 0 + } else { + factorial(n) / (factorial(k) * factorial(n - k)) + } +} + pub fn get_divisors(n: u64) -> Vec { let mut divisors = HashSet::from([1]); let mut potential_divisor = 2;