#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; template vector make_v(U size, const T& init){ return vector(static_cast(size), init); } template auto make_v(U size, Ts... rest) { return vector(static_cast(size), make_v(rest...)); } template void chmin(T &a, const T &b){ a = (a < b ? a : b); } template void chmax(T &a, const T &b){ a = (a > b ? a : b); } int main() { int n, m, p; cin >> n >> m >> p; vector a(n); vector b(n); for (auto &&i : a) scanf("%d", &i); int X = 0; int maxx = *max_element(a.begin(),a.end()); if(maxx > m) { cout << 1 << "\n"; return 0; } for (int i = 0; i < n; ++i) { while(a[i]%p == 0) { a[i] /= p; b[i]++; } X = max(X, b[i]); } auto x = *max_element(a.begin(),a.end()); if(x == 1) { puts("-1"); return 0; } vector mx(X+1, 0); for (int i = 0; i < n; ++i) { chmax(mx[b[i]], a[i]); } vector mae(X+1, 0); for (int i = 0; i <= X; ++i) { if(mx[i] == 0) continue; mae[i] = mx[i]; for (int j = 0; j < X; ++j) { mae[i] *= p; } } vector dp(10000, 1); int ans = INF; for (int i = 0; i < 10000; ++i) { if(dp[i] > m){ cout << i << "\n"; return 0; } if(dp[i]*maxx > m){ cout << i+1 << "\n"; return 0; } for (int j = 0; j <= X; ++j) { chmax(dp[i+j+1], dp[i]*mx[j]); } } return 0; }