diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 0000000..d5cb60d --- /dev/null +++ b/src/util.rs @@ -0,0 +1,15 @@ + +pub fn gcd(a: usize, b: usize) -> usize { + if a == 0 || b == 0 { return 0; } + let min = usize::min(a, b); + let max = usize::max(a, b); + + let remainder = max % min; + if remainder == 0 { return min; } + else { return gcd(min, remainder); } +} + +pub fn lcm(a: usize, b: usize) -> usize { + return ( a * b ) / gcd(a, b); +} +