#include #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--) #define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++) #define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--) #define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; pair fc(int a, int p){ int res = 1; while(a % p == 0){ res++; a /= p; } return {a, res}; } int main(){ int n, m, p; cin >> n >> m >> p; if(m == 1){ cout << 0 << endl; return 0; } ll now = 1; vector> ab; rep(i, n){ int in; cin >> in; now = max((int)now, in); auto [a, b] = fc(in, p); if(a != 1){ ab.push_back({a, b}); } } int ans = 1001001001; if(now <= m){ for(auto [a, b] : ab){ ll nw = now; int add = 1; while(nw <= m){ nw *= a; add += b; } ans = min(ans, add); } } if(ab.size() == 0) ans = -1; cout << ans << endl; return 0; }