use std::io::*; const INF: usize = 1 << 30; const MAX: usize = 1000; 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 n: usize = itr.next().unwrap().parse().unwrap(); let m: usize = itr.next().unwrap().parse().unwrap(); let p: usize = itr.next().unwrap().parse().unwrap(); let a: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let mut max = 0; let mut b = Vec::new(); for &e in a.iter() { max = std::cmp::max(max, e); let mut cnt = 1; let mut x = e; while x % p == 0 { x /= p; cnt += 1; } if x == 1 { continue; } b.push((cnt, x)); } b.sort(); let mut dp = vec![0; MAX]; dp[0] = 1; for &(cnt, x) in b.iter() { for i in 0..MAX { if dp[i] > m || cnt + i >= MAX { break; } dp[i + cnt] = std::cmp::max(dp[i + cnt], dp[i] * x); } } let mut ans = INF; for i in 0..MAX { if dp[i] > m { ans = std::cmp::min(ans, i); } else if dp[i] * max > m { ans = std::cmp::min(ans, i + 1); } } if ans == INF { println!("-1"); } else { println!("{}", ans); } }