You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
701 B
40 lines
701 B
12 months ago
|
use std::collections::HashMap;
|
||
|
fn get_hs(n: u32) -> HashMap<u8, u32> {
|
||
|
let mut nn = n;
|
||
|
let mut res = HashMap::<u8, u32>::new();
|
||
|
while nn > 0 {
|
||
|
let c = (nn%10) as u8;
|
||
|
if res.contains_key(&c) {
|
||
|
res.insert(c, res[&c] + 1);
|
||
|
} else {
|
||
|
res.insert(c, 1);
|
||
|
}
|
||
|
nn /= 10;
|
||
|
}
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
|
||
|
fn test(n: u32) -> bool {
|
||
|
let hm = get_hs(n);
|
||
|
for i in 2..=6 {
|
||
|
let m = n * i;
|
||
|
let hmi = get_hs(m);
|
||
|
if hmi != hm {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
for i in 1..999999 {
|
||
|
|
||
|
if test(i) {
|
||
|
println!("{}", i);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|