fn main() { let stdin = std::io::stdin(); let mut rd = ProconReader::new(stdin.lock()); let n: usize = rd.get(); let m: u64 = rd.get(); let p: u64 = rd.get(); let a: Vec = rd.get_vec(n); let a: Vec = a.into_iter().filter(|&y| y != 1).collect(); if a.is_empty() { println!("-1"); return; } let max = *a.iter().max().unwrap(); if max > m { println!("1"); return; } let a: Vec = a .into_iter() .filter(|&y| { let mut y = y; while y % p == 0 { y /= p; } y != 1 }) .collect(); if a.is_empty() { println!("-1"); return; } let mut ans = std::u32::MAX; for y in a { let mut x = 1; let mut cnt = 0; while x <= m { if x * max > m { cnt += 1; break; } while x % p == 0 { x /= p; cnt += 1; } x *= y; cnt += 1; } ans = ans.min(cnt); } assert!(ans < std::u32::MAX); println!("{}", ans); } pub struct ProconReader { r: R, line: String, i: usize, } impl ProconReader { pub fn new(reader: R) -> Self { Self { r: reader, line: String::new(), i: 0, } } pub fn get(&mut self) -> T where T: std::str::FromStr, ::Err: std::fmt::Debug, { self.skip_blanks(); assert!(self.i < self.line.len()); assert_ne!(&self.line[self.i..=self.i], " "); let line = &self.line[self.i..]; let end = line.find(' ').unwrap_or_else(|| line.len()); let s = &line[..end]; self.i += end; s.parse() .unwrap_or_else(|_| panic!("parse error `{}`", self.line)) } fn skip_blanks(&mut self) { loop { let start = self.line[self.i..].find(|ch| ch != ' '); match start { Some(j) => { self.i += j; break; } None => { self.line.clear(); self.i = 0; let num_bytes = self.r.read_line(&mut self.line).unwrap(); assert!(num_bytes > 0, "reached EOF :("); self.line = self.line.trim_end_matches(&['\r', '\n'][..]).to_string(); } } } } pub fn get_vec(&mut self, n: usize) -> Vec where T: std::str::FromStr, ::Err: std::fmt::Debug, { (0..n).map(|_| self.get()).collect() } }