diff --git a/023/main.rs b/023/main.rs new file mode 100644 index 0000000..25e0c04 --- /dev/null +++ b/023/main.rs @@ -0,0 +1,47 @@ +const NUMS_LEN: usize = 28124; + + +fn is_abundant(n: usize) -> bool { + let mut s = 0; + for i in 1..n { + if n % i == 0 { + s += i; + } + } + return s > n; +} + +fn main() { + //let r = is_abundant(12); + let mut ambs = Vec::::new(); + + for i in 1..NUMS_LEN { + if is_abundant(i) { + ambs.push(i); + } + } + + let mut candidates: [bool; NUMS_LEN] = [false; NUMS_LEN]; + + for a in &ambs { + //println!("a: {}", a); + for b in &ambs { + if a + b < NUMS_LEN { + candidates[a + b] = true; + } + } + } + + let mut res_sum = 0usize; + + for i in 0..NUMS_LEN { + if !candidates[i] { + res_sum += i; + } + } + + println!("result: {}", res_sum); + + //println!("is abundant: {}", r); +} +