import sys
input=sys.stdin.readline

N,M,P=map(int,input().split())
A=set(map(int,input().split()))
A=list(A)

Max=max(A)

T={}
for b in A:
    a=b
    m=1
    while b%P==0:
        b//=P

    if b>1 and (b not in T or T[b]>m):
        T[b]=m

if not T and M<=Max:
    print(-1)
    exit(0)

X=float("inf")
for b in T:
    m=T[b]
    k=1
    x=1
    while x*Max<=M:
        x*=b
        k+=m
    X=min(X,k)
print(X)