You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
834 B
48 lines
834 B
1 year ago
|
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);
|
||
|
}
|
||
|
|