use std::io::*; const INF: usize = 1 << 30; 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(); if max > m { println!("1"); } else { let mut dp = vec![0; 100]; dp[0] = 1; for &(cnt, x) in b.iter() { for i in 0..100 { if dp[i] > m || cnt + i >= 100 { break; } dp[i + cnt] = std::cmp::max(dp[i + cnt], dp[i] * x); } } let mut ans = INF; for i in 1..100 { if dp[i] > m { ans = std::cmp::min(ans, i); } } if ans == INF { println!("-1"); } else { println!("{}", ans); } } }