Find primes in numbers
// Find primes in numbers
fn prime_factors(n: i64) -> String {
let mut n = n as u64;
let mut d = 2;
let mut mem = std::collections::BTreeMap::new();
while d <= n {
if n % d == 0 {
n /= d;
let old = mem.entry(d).or_insert(0);
*old += 1;
} else {
d += 1;
}
}
mem.iter().map(|(key, val)| match *val {
1 => format!("({})", key),
_ => format!("({}**{})", key, val),
}).collect::<String>()
}
fn main() {
println!("Primes in numbers = {} ", prime_factors(7775460));
println!("Primes in numbers = {} ", prime_factors(13*17*3*26));
println!("Primes in numbers = {} ", prime_factors(14));
}