struct Num { n: u32, digits: Vec } impl Num { fn new(n: u32) -> Num { let mut dsr = Vec::new(); let mut k = n; while k != 0 { let a = (k % 10) as u8; k /= 10; dsr.push(a); } dsr.reverse(); return Num { n, digits: dsr }; } fn check(&self) -> bool { let mut sum = 0u32; for k in &self.digits { let d = *k as u32; sum += d * d * d * d * d; } return sum == self.n; } } fn main() { //let n = Num::new(9474); //for d in &n.digits { print!("{}", d) } //println!(""); //println!("{}", n.check()); let mut sum = 0u32; for i in 2..5_000_000u32 { let n = Num::new(i); if n.check() { println!("{}", n.n); sum += n.n; } } println!("{}", sum); }