use std::io::*; fn permutation(n: usize, p: &mut Vec, used: &mut Vec, all: &mut Vec>) { if p.len() == n { all.push(p.to_vec()); return; } for i in 0..n { if !used[i] { p.push(i); used[i] = true; permutation(n, p, used, all); p.pop(); used[i] = false; } } } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let k: usize = itr.next().unwrap().parse().unwrap(); let mut p: Vec = Vec::new(); let mut out: Vec> = Vec::new(); let mut used: Vec = vec![false; 8]; permutation(8, &mut p, &mut used, &mut out); let mut ans = 0; for x in out { let mut d = 0; for y in x { d *= 10; d += y + 1 } if d % k == 0 { ans += 1; } } println!("{}", ans); }