var m1,m2,m,tot:longint; b,t:array[1..6] of longint; n,i,j,s,c,ans,ans2,ans3:longint; ab:boolean; function ceil(x:real):longint; begin if frac(x)>1e-8 then exit(trunc(x)+1); exit(trunc(x)); end; function MAX(a,b:longint):longint; begin if a>b then exit(a) else exit(b); end; function MIN(a,b:longint):longint; begin if a<b then exit(a) else exit(b); end; begin assign(input,'cell.in'); reset(input); assign(output,'cell.out'); rewrite(output); readln(n,m1,m2); tot:=0; m:=m1; for i:=2 to m do begin if m1 mod i=0 then begin inc(tot); b[tot]:=i; while m1 mod i=0 do begin m1:=m1 div i; inc(t[tot]); end; end; end; for i:=1 to tot do t[i]:=t[i]*m2; ans:=maxlongint; for i:=1 to n do begin read(s); ans2:=0; for j:=1 to tot do begin c:=0; while s mod b[j]=0 do begin s:=s div b[j]; inc(c); end; if c=0 then begin ans2:=maxlongint; break; end else begin ans3:=ceil(t[j]/c); ans2:=MAX(ans2,ans3); end; end; ans:=MIN(ans,ans2); end; if ans=maxlongint then ans:=-1; writeln(ans); close(input); close(output); end.