Browse Source

030 ok

master
Coin de Gamma 1 year ago
parent
commit
9da9ef3fc0
  1. 44
      030/main.rs

44
030/main.rs

@ -0,0 +1,44 @@
struct Num {
n: u32,
digits: Vec<u8>
}
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);
}
Loading…
Cancel
Save