From 9da9ef3fc01342251031ddfd8c7e62d9a0b47053 Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Thu, 9 Nov 2023 08:27:38 +0000 Subject: [PATCH] 030 ok --- 030/main.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 030/main.rs diff --git a/030/main.rs b/030/main.rs new file mode 100644 index 0000000..1db6940 --- /dev/null +++ b/030/main.rs @@ -0,0 +1,44 @@ +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); +} + +