/** * author: shu8Cream * created: 08.01.2021 21:06:40 **/ #include using namespace std; #define rep(i,n) for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using P = pair; using vi = vector; using vvi = vector; const int MX = 1000005; struct Sieve { int n; vector f, primes; Sieve(int n=1):n(n+1), f(n+1) { f[0] = f[1] = -1; for(ll i=2; i <= n; ++i){ if(f[i]) continue; primes.push_back(i); f[i]=i; for(ll j=i*i; j <= n; j+=i){ if(!f[j]) f[j]=i; } } } bool isPrime(int x){ return f[x] == x;} //xの素因数分解の要素の配列 vector factorList(int x){ vector res; while(x != 1){ res.push_back(f[x]); x /= f[x]; } return res; } //xの素因数分解の要素をRunLength圧縮 vector

factor(int x){ vector fl = factorList(x); if(fl.size() == 0) return {}; vector

res(1, P(fl[0], 0)); for(int p:fl){ if(res.back().first == p){ res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Sieve sieve(1e8); int n,m,p; cin >> n >> m >> p; vi a(n); rep(i,n) cin >> a[i]; map mp; rep(i,n){ auto f = sieve.factor(a[i]); for(auto p : f){ mp[p.first] += p.second; } } bool f = true; int tmp=0; for(auto p : mp){ if(p.first!=2) f=false; tmp = p.first; } if(f){ cout << -1 << endl; return 0; } int cnt = 0; rep(i,n) if(a[i]%tmp==0) cnt=max(cnt, a[i]); while(cnt%p==0){ cnt/=p; } tmp = 1; int ans=0; while(m>tmp){ tmp*=cnt; ans++; } cout << ans << endl; }