26 lines
653 B
Rust
26 lines
653 B
Rust
fn main() {
|
|
let mut total = 0;
|
|
for x in 1..10_000 {
|
|
let candidate = divisors_sum(x);
|
|
let c_sum = divisors_sum(candidate);
|
|
if x != candidate && x < candidate && x == c_sum {
|
|
println!("x: {}, candidate: {}, c_sum: {}", x, candidate, c_sum);
|
|
total += x+candidate;
|
|
}
|
|
}
|
|
println!("{}", total);
|
|
}
|
|
|
|
fn divisors_sum(dividend: usize) -> usize {
|
|
let mut divisor = 2;
|
|
let mut total = 1;
|
|
while divisor * divisor < dividend {
|
|
if dividend % divisor == 0 {
|
|
total += divisor;
|
|
total += dividend / divisor;
|
|
}
|
|
divisor+=1;
|
|
}
|
|
total
|
|
}
|