-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.rs
41 lines (36 loc) · 846 Bytes
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
pub struct Solution;
impl Solution {
pub fn common_factors(a: i32, b: i32) -> i32 {
let min = a.min(b);
let mut i = 1;
let mut result = 0;
while i * i <= min {
if min % i == 0 {
if a % i == 0 && b % i == 0 {
result += 1;
}
if i * i != min && a % (min / i) == 0 && b % (min / i) == 0 {
result += 1;
}
}
i += 1;
}
result
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test1() {
assert_eq!(Solution::common_factors(12, 6), 4);
}
#[test]
fn test2() {
assert_eq!(Solution::common_factors(25, 30), 2);
}
#[test]
fn test3() {
assert_eq!(Solution::common_factors(850, 442), 4);
}
}