/* #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") //*/ #include // #include using namespace std; // using namespace atcoder; #define DEBUG(x) cerr<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair template pair operator+(const pair &s, const pair &t) { return pair(s.first + t.first, s.second + t.second); } template pair operator-(const pair &s, const pair &t) { return pair(s.first - t.first, s.second - t.second); } template ostream& operator<<(ostream& os, pair p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0}; // vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 }; struct Setup_io { Setup_io() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(25); } } setup_io; const ll MOD = 1000000007; // const ll MOD = 998244353; // #define mp make_pair //#define endl '\n' signed main() { ll n, m, p; cin >> n >> m >> p; vl a(n); vl w(n), v(n); bool hi1 = false; rep (i, n) { cin >> a[i]; w[i] = 1; v[i] = a[i]; while (v[i] % p == 0) { w[i]++; v[i] /= p; } if (v[i] != 1) hi1 = true; } if (not hi1) { cout << -1 << endl; return 0; } const int N = 33; vl v2(N, 1); rep (i, n) { chmax(v2[w[i]], v[i]); } swap(v, v2); // DEBUG_VEC(v); const int M = 10000; vll dp(N + 1, vl(M, -INF)); dp[0][0] = 1; rep (i, N) { rep (j, M) { if (dp[i][j] == -INF) continue; // if (dp[i][j] >= m) continue; if (v[i] == 1) { chmax(dp[i + 1][j], dp[i][j]); } else { ll mul = dp[i][j]; ll add = 0; while (true) { chmax(dp[i + 1][j + add * i], mul); if (mul >= m) break; add++; mul *= v[i]; } } } } // DEBUG_MAT(dp); rep (j, M) { if (dp[N][j] >= m) { cout << j << endl; return 0; } } }