#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } signed main(){ int n;ll m,p;cin>>n>>m>>p; vector v(60,-1); ll unko=0; rep(i,n){ ll x;cin>>x; chmax(unko,x); ll t=0; while(x%p==0) x/=p,t++; if(x>1) chmax(v[t],x); } map dp; dp[1]=0; rep(i,60)if(v[i]>0){ for(auto s:dp){ if(s.first<=m){ if(!dp.count(s.first*v[i])){ if(s.first*v[i]>m) dp[s.first*v[i]]=s.second+1; else dp[s.first*v[i]]=s.second+i+1; } else{ if(s.first*v[i]>m) chmin(dp[s.first*v[i]],s.second+1); else chmin(dp[s.first*v[i]],s.second+i+1); } } } } ll res=LINF; for(auto s:dp){ if(s.first>m) chmin(res,s.second); else if(s.first*unko>m) chmin(res,s.second+1); } if(res==LINF) cout<<-1<