use std::cmp::*; #[allow(dead_code)] mod scanner { use std; use std::io::Read; use std::str::FromStr; use std::str::SplitWhitespace; pub struct Scanner<'a> { it: SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next(&mut self) -> T { match self.it.next().unwrap().parse::() { Ok(v) => v, _ => panic!("Scanner error"), } } pub fn next_chars(&mut self) -> Vec { self.next::().chars().collect() } pub fn next_vec(&mut self, len: usize) -> Vec { (0..len).map(|_| self.next()).collect() } } pub fn read_string() -> String { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s } } fn main() { let sc = scanner::read_string(); let mut sc = scanner::Scanner::new(&sc); let n: usize = sc.next(); let m: usize = sc.next(); let p: usize = sc.next(); let mut a = sc.next_vec::(n); let mut am = 1; let mut map = std::collections::BTreeMap::::new(); for i in 0..n { am = max(am, a[i]); let mut x = 1; while a[i] % p == 0 { a[i] /= p; x += 1; } if a[i] != 1 { let y = map.entry(x).or_insert(1); *y = max(*y, a[i]); } } if map.is_empty() { println!("-1"); return; } let mut dp = vec![0usize; 100000]; dp[0] = 1; for i in 1.. { if dp[i - 1] * am > m { println!("{}", i); return; } for (&k, &v) in map.iter() { if k <= i { dp[i] = max(dp[i], dp[i - k] * v); } } } }