/* -*- coding: utf-8 -*- * * 1330.cc: No.1330 Multiply or Divide - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int L = 31 * 31; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N], bs[MAX_N], cs[MAX_N], dp[L + 1]; /* subroutines */ /* main */ int main() { int n, m, p; scanf("%d%d%d", &n, &m, &p); int maxa = 0; for (int i = 0; i < n; i++) { scanf("%d", as + i); if (maxa < as[i]) maxa = as[i]; } if (maxa > m) { puts("1"); return 0; } int k = 0; for (int i = 0; i < n; i++) { int b = as[i], dc = 1; while (b % p == 0) b /= p, dc++; if (b > 1) { bs[k] = b, cs[k] = dc; k++; } } if (k == 0) { puts("-1"); return 0; } int ma = m / maxa; memset(dp, -1, sizeof(dp)); dp[0] = 1; for (int i = 0; i <= L; i++) if (dp[i] >= 0) { if ((ll)dp[i] > ma) { printf("%d\n", i + 1); return 0; } for (int j = 0; j < k; j++) if (i + cs[j] <= L) dp[i + cs[j]] = min(max(dp[i + cs[j]], (ll)dp[i] * bs[j]), ma + 1); } puts("-1"); return 0; }