#include #include using namespace atcoder; using namespace std; using ll = long long; using mint = modint998244353; int main() { int N;ll M, P;cin >> N >> M >> P; int K = 1000; vector A(K + 1, 0); bool ret = false; for (int i = 1;i <= N;i++) { ll a;cin >> a; if (a > M) { cout << 1 << endl; return 0; } int c = 0; while (a % P == 0) { c++; a /= P; } A[c] = max(A[c], a); if (a != 1) { ret = true; } } if (!ret) { cout << -1 << endl; return 0; } vector dp(K + 1, 1); ll ep = 1; for (int i = 0;i <= 35;i++) { if (A[i] == 0) { if (ep > M) continue; ep *= P; continue; } vector ndp(K + 1, 1); ll x = A[i]; ll y = ep * A[i]; for (int j = 1;j <= K;j++) { //iをつかわない ndp[j] = dp[j]; if (dp[j] == M + 1) continue; //iをつかう //いっかいかけるでoverになるばあい if (y * ndp[j - 1] > M) { ndp[j] = M + 1; continue; } //ならなかったばあい if (i + 1 <= j) { ndp[j] = max(ndp[j], min(M + 1, x * ndp[j - i - 1])); } } swap(dp, ndp); ep *= P; } for (int i = 1;i <= K;i++) { if (dp[i] == M + 1) { cout << i << endl; return 0; } } }