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.
45 lines
889 B
45 lines
889 B
1 year ago
|
use std::collections::HashSet;
|
||
|
|
||
|
fn pr(s: &Vec<u8>) {
|
||
|
for c in s.iter() { print!("{}", c); }
|
||
|
println!("");
|
||
|
}
|
||
|
|
||
|
fn dv(k: u32) -> Vec<u8> {
|
||
|
let mut rms = HashSet::new();
|
||
|
let mut res: Vec<u8> = Vec::new();
|
||
|
let mut n = 1u32;
|
||
|
loop {
|
||
|
if rms.contains(&n) {
|
||
|
break;
|
||
|
}
|
||
|
rms.insert(n);
|
||
|
if n == 0 { res.clear(); res.push(0); break; }
|
||
|
while n < k { n *= 10; res.push(0u8); }
|
||
|
let m = n / k;
|
||
|
if m > 10 {
|
||
|
println!("fail! {}", m);
|
||
|
}
|
||
|
res.pop();
|
||
|
//print!("{}", m);
|
||
|
res.push(m as u8);
|
||
|
n = n - m * k;
|
||
|
}
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let mut max = 0;
|
||
|
let mut max_d = 0;
|
||
|
for i in 1..1000 {
|
||
|
let r = dv(i);
|
||
|
if r.len() > max {
|
||
|
max_d = i;
|
||
|
max = r.len();
|
||
|
}
|
||
|
//pr(&r);
|
||
|
}
|
||
|
println!("{}", max_d);
|
||
|
}
|
||
|
|