fn p(i: &mut [u64]) -> bool { let mut j = i.len() - 1; let mut k = j; while j > 0 && i[j - 1] >= i[j] { j -= 1 } if j == 0 { return false; } while i[k] <= i[j - 1] { k -= 1 } i.swap(j - 1, k); i[j..].reverse(); true } fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let k: u64 = s.trim().parse().unwrap(); let mut i: Vec<_> = (1..9).collect(); let mut a = 0; loop { let x = i.iter().fold(0, |a, &b| a * 10 + b); if x % k == 0 { a += 1 } if !p(&mut i) { break } } println!("{a}") }