Browse Source

023 ok

master
Coin de Gamma 9 months ago
parent
commit
e581fe779f
  1. 47
      023/main.rs

47
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::<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…
Cancel
Save