#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; using ull = unsigned long long; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //template T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); }return a; } //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353; int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); ll n, m, P; cin >> n >> m >> P; vector a(n); ll tm = 1; map b; for (auto& e : a) { cin >> e; chmax(tm, e); ll cnt = 1; while (e % P == 0) e /= P, cnt += 1; if (e > 1) { if (b.count(e)) chmin(b[e], cnt); else b[e] = cnt; } } if (tm > m) { cout << 1 << "\n"; return 0; } ll mx = *max_element(a.begin(), a.end()); if (mx == 1) { cout << -1 << "\n"; } else { map mp; mp[1] = 0; ll res = INF; auto update = [&](ll x, ll y) { if (mp.count(x)) chmin(mp[x], y); else mp[x] = y; }; while (!mp.empty() and mp.begin()->first <= m) { if (mp.begin()->first * tm > m) { chmin(res, mp.begin()->second + 1); mp.erase(mp.begin()); } else { auto [t, cnt] = *mp.begin(); if (cnt >= res) continue; mp.erase(mp.begin()); for (auto [f, s] : b) { if (f == 1) continue; if(cnt + s < inf) update(t * f, cnt + s); } } } cout << res << "\n"; } }