From 55b1708ac23038d2fd617990fd62709b0024f813 Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Wed, 8 Nov 2023 07:35:50 +0000 Subject: [PATCH] 029 ok --- 029/main.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 029/main.rs diff --git a/029/main.rs b/029/main.rs new file mode 100644 index 0000000..648efde --- /dev/null +++ b/029/main.rs @@ -0,0 +1,62 @@ +use std::collections::HashSet; + +struct PN { + a: u32, + b: u32, + ps: String, +} + +impl PN { + fn new(a: u32, b: u32) -> PN { + PN { a, b, ps: String::new() } + } + + fn simplify(&mut self, ps: &Vec ) { + let mut n = self.a; + for p in ps { + let mut k = 0; + while n % p == 0 { k += 1; n /= p; } + k *= self.b; + if k > 0 { + self.ps += &format!("{},{}.", p, k); + } + } + } +} + +fn er() -> Vec { + let mut ns = Vec::new(); + let mut res = Vec::new(); + for _i in 0..=100 { ns.push(true); } + let mut k = 1; + loop { + let mut found_next_k = false; + for j in k + 1..=100 { if ns[j] { k = j; found_next_k = true; break; } } + if !found_next_k { break; } + res.push(k as u32); + for i in (k+k..=100).step_by(k) { ns[i] = false } + } + + return res; +} + +fn main() { + let mut hs = HashSet::new(); + let ps = er(); + for p in &ps { print!("{} ", p); } + println!(""); + + for a in 2..=100 { + for b in 2..=100 { + let mut pn = PN::new(a, b); + pn.simplify(&ps); + //println!("{}", pn.ps); + hs.insert(pn.ps); + } + } + + println!("{}", hs.len()); + + +} +