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.
95 lines
2.1 KiB
95 lines
2.1 KiB
// sorry it's mess i am lazy to clearup |
|
|
|
use std::collections::HashMap; |
|
use std::collections::HashSet; |
|
|
|
const N: u32 = 10_000; |
|
|
|
struct Amd { |
|
pub d: Vec<u32>, |
|
pub e: HashMap<u32, Vec<u32>>, |
|
pub a: HashSet<u32> |
|
} |
|
|
|
impl Amd { |
|
fn new() -> Amd { |
|
return Amd { |
|
d: Vec::new(), |
|
e: HashMap::new(), |
|
a: HashSet::new() |
|
}; |
|
} |
|
|
|
fn precalc(&mut self) { |
|
self.d.push(0); |
|
//let mut sum_ams = 0u32; |
|
for i in 1..=N { |
|
let d = get_d(i); |
|
let d_ = get_d(d); |
|
if d_ == i && i != d && i > d { |
|
println!("found ({} vs {})", i, d); |
|
//sum_ams += i; |
|
if d != i { |
|
//sum_ams += d + i; |
|
self.a.insert(d); |
|
self.a.insert(i); |
|
} |
|
} |
|
continue; |
|
if d > i { |
|
println!("yo big {} vs {}", i, d); |
|
} |
|
self.d.push(d); |
|
if self.e.get(&d).is_none() { |
|
let mut v = Vec::new(); |
|
v.push(i); |
|
self.e.insert(d, v); |
|
} else { |
|
let v = self.e.get_mut(&d).unwrap(); |
|
v.push(i); |
|
} |
|
} |
|
|
|
let mut sum_ams = 0u32; |
|
for i in self.a.iter() { |
|
sum_ams += i; |
|
} |
|
println!("sum_ams: {}", sum_ams); |
|
} |
|
|
|
fn ams(&self) { |
|
for (k, v) in self.e.iter() { |
|
if v.len() > 1 { |
|
for n in v { |
|
//if self.d[k as usize] = n { |
|
// println!("") |
|
//} |
|
} |
|
//print!("{} -> ", k); |
|
//for n in v { |
|
// print!("{} ", n); |
|
//} |
|
//println!(""); |
|
} |
|
} |
|
} |
|
} |
|
|
|
fn get_d(n: u32) -> u32 { |
|
let mut res = 0; |
|
for i in 1..n { |
|
if n % i == 0 { |
|
res += i; |
|
} |
|
} |
|
return res; |
|
} |
|
|
|
fn main() { |
|
let mut amd = Amd::new(); |
|
amd.precalc(); |
|
amd.ams(); |
|
//println!("rr: {}", rr); |
|
//println!("hey 021"); |
|
} |
|
|
|
|