#include using namespace std; #define REP(i, n) FOR(i, 0, (n)) #define FOR(i, a, b) for(int i=(a); i<(b); i++) #define LAR(a, b) ((a)=max((a),(b))) #define SML(a, b) ((a)=min((a),(b))) using ll = long long; using ld = long double; using vi = vector; using vl = vector; using pii = pair; using vpii = vector>; template using pque = priority_queue, greater>; #define PB push_back #define EB emplace_back #define MP make_pair #define ALL(a) (a).begin(), (a).end() #ifdef LOCAL_DEBUG #define DEBUG(...) printf(__VA_ARGS__) #else #define DEBUG(...) #endif ll a[212345]; ll b[212345]; int main(){ int n; ll m, p; scanf("%d%lld%lld", &n, &m, &p); REP(i, n) scanf("%lld", a+i); REP(i, n){ b[i] = a[i]; while(b[i] % p == 0) b[i] /= a[i]; } ll *y = max_element(a, a+n); ll *z = max_element(b, b+n); int ans = 0; ll x = 1; while(x <= m){ if(x * *y > m) { ans++; break; } if(*z == 1) { ans = -1; break; } x *= *(z-b+a); ans++; while(x % p == 0){ x /= p; ans++; } } printf("%d\n", ans); }