#include using namespace std; using lint = long long; using plint = pair; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; } void answer(lint x) { cout << x << '\n'; exit(0); } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N, M, P; cin >> N >> M >> P; lint maxi = 0; vector te2w; vector te2amax(32, 0); while (N--) { lint a; cin >> a; chmax(maxi, a); int te = 1; while (a % P == 0) a /= P, te++; chmax(te2amax[te], a); } FOR(t, 1, te2amax.size()) if (te2amax[t] > 1) te2w.emplace_back(t, te2amax[t]); const lint tgt = (M + 1 + maxi - 1) / maxi; priority_queue, greater> pq; pq.emplace(1, -1); while (pq.size()) { auto [D, val] = pq.top(); pq.pop(); if (abs(val) >= tgt) { answer(D); } for (auto [dd, a] : te2w) { pq.emplace(D + dd, val * a); } } puts("-1"); }