#include using namespace std; #define rep(i,n) for (long long i = 0; i < (n); ++i) using ll = long long; using P = pair; using PP = pair; using vec = vector; using vecp = vector

; using mat = vector; using matp = vector; const ll MOD = 1e9+7; const ll INF = 1e18; #define all(v) v.begin(), v.end() int main(){ ll N,M,P; cin >> N >> M >> P; vec A(N),B(30,0); rep(i,N){ cin >> A.at(i); ll t=0; while(A.at(i)%P==0){ t++; A.at(i)/=P; } B.at(t)=max(B.at(t),A.at(i)); } rep(i,30){ if(B.at(i)>1){ break; } if(i==29){ cout << -1 << endl; return 0; } } vec dp(900,0); dp.at(0)=1; rep(i,900){ if(dp.at(i)>M){ cout << i << endl; return 0; } rep(j,30){ dp.at(i+j+1)=max(dp.at(i+j+1),dp.at(i)*B.at(j)); } } }