Coin de Gamma
1 year ago
1 changed files with 47 additions and 0 deletions
@ -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::<usize>::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);
|
||||
} |
||||
|
Loading…
Reference in new issue