def aa(s): global m,c if s>=m: return 0 if s*c>=m: return 1 if s in v: return v[s] res=1<<30 for i in range(1,len(y)): if y[i]: res=min(res,aa(s*y[i])+i) v[s]=res return res n,m,p=map(int,input().split()) a=list(map(int,input().split())) x={};c=max(a) for i in a: d=1 while i%p==0: i//=p;d+=1 if i==1: continue if i in x: x[i]=min(x[i],d) else: x[i]=d if len(x)==0: print(-1) exit() y=[0]*61 for i,j in x.items(): y[j]=max(y[j],i) v={} aa(1);print(v[1])