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 } } trait Monoid { fn id() -> Self; fn f(a: Self, b: Self) -> Self; } #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] enum MinInt { Val(i64), Maximal, } #[allow(dead_code)] impl MinInt { fn unwrap(self) -> i64 { if let Self::Val(x) = self { x } else { panic!(); } } fn map(self, f: F) -> Self where F: Fn(i64) -> i64, { if let Self::Val(x) = self { Self::Val(f(x)) } else { Self::Maximal } } fn map2(self, b: Self, f: F) -> Self where F: Fn(i64, i64) -> i64, { match (self, b) { (Self::Val(x), Self::Val(y)) => Self::Val(f(x, y)), _ => Self::Maximal, } } fn get_or(self, default: i64) -> i64 { match self { Self::Val(x) => x, _ => default, } } } impl std::ops::Mul for MinInt { type Output = Self; fn mul(self, other: Self) -> Self { if self < other { self } else { other } } } impl Monoid for MinInt { fn id() -> Self { MinInt::Maximal } fn f(a: Self, b: Self) -> Self { a * b } } use MinInt::*; 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 b = vec![]; let mut c = vec![]; for i in 0..n { if a[i] % p == 0 { while a[i] % p == 0 { a[i] /= p; } b.push(a[i]); } else { c.push(a[i]); } } b.sort(); b.reverse(); c.sort(); c.reverse(); let mut ans = Maximal; if !b.is_empty() && b[0] != 1 { let mut x = 1; let mut y = 0; while x <= m { if !c.is_empty() && x * c[0] > m { y += 1; break; } x *= b[0]; y += 2; } ans = ans * Val(y); } if !c.is_empty() && c[0] != 1 { let mut x = 1; let mut y = 0; while x <= m { x *= c[0]; y += 1; } ans = ans * Val(y); } println!("{}", ans.get_or(-1)); }