struct Scanner { r: R, buf: Vec } impl Scanner { fn new(r: R) -> Scanner { Scanner { r, buf: Vec::with_capacity(8000) } } fn next(&mut self) -> &str { self.buf.clear(); loop { let (done, used) = { let available = self.r.fill_buf().unwrap(); match available.iter().position(|b| !b.is_ascii_whitespace()) { Some(i) => (true, i), None => (false, available.len()), } }; self.r.consume(used); if done || used == 0 { break; } } loop { let (done, used) = { let available = self.r.fill_buf().unwrap(); match available.iter().position(|b| b.is_ascii_whitespace()) { Some(i) => { self.buf.extend_from_slice(&available[..i]); (true, i) } None => { self.buf.extend_from_slice(&available); (false, available.len()) } } }; self.r.consume(used); if done || used == 0 { unsafe { return std::str::from_utf8_unchecked(&self.buf); } } } } } macro_rules! parse { ($s:expr, Chars) => ($s.chars().collect::>()); ($s:expr, Bytes) => ($s.bytes().collect::>()); ($s:expr, Usize1) => (parse!($s, usize) - 1); ($s:expr, $t:ty) => ($s.parse::<$t>().unwrap()); } macro_rules! read { ($sc:expr, [$t:tt; $n:expr]) => ( (0..$n).map(|_| read!($sc, $t)).collect::>() ); ($sc:expr, ($($t:tt),*)) => (($(read!($sc, $t)),*)); ($sc:expr, $t:ident) => (parse!($sc.next(), $t)); ($sc:expr, $($t:tt),*) => (($(read!($sc, $t)),*)); } fn main() { use std::io::Write; let (stdin, stdout) = (std::io::stdin(), std::io::stdout()); let mut sc = Scanner::new(stdin.lock()); let mut wr = std::io::BufWriter::new(stdout.lock()); macro_rules! scan { ($($t:tt)*) => (read!(sc, $($t)*)); } macro_rules! println { ($($arg:tt)*) => (writeln!(wr, $($arg)*).ok()); } let (n, m, p) = scan!(usize, i64, i64); let a = scan!([i64; n]); let mut ans = std::u64::MAX; for a in a { let mut b = a; let mut x = 0; while b % p == 0 { b /= p; x += 1; } if b == 1 { continue; } let mut b = a; let mut y = 0; while b <= m { b *= a; y += 1; } ans = ans.min((1 + x) * y + 1); } println!("{}", ans as i64); }