感觉思路挺对但不知道为啥错,用各种玄学改法改了改还是50
#include <bits/stdc++.h>
using namespace std;
long long a[1001],b[1005];
long long n,m1,m2,cnt=0,s,t,tmp,ans;
bool f;
long long read(){
long long f=1,x=0;
char ch;
do{
ch=getchar();
if(ch=='-') f=-1;
}while(ch<'0'||ch>'9');
do{
x=(x<<1)+(x<<3)+ch-'0';
ch=getchar();
}while(ch<='9'&&ch>='0');
return f*x;
}
int main(){
n=read(),m1=read(),m2=read();
int m=sqrt(m1);
for(int i=2;i<=m;i++)
if(m1%i==0){
a[cnt]=i;
while(m1%i==0){
b[cnt]++;
m1/=i;
}
cnt++;
}
if(m1!=1) a[cnt]=m1,b[cnt]=1,cnt++;
ans=1<<30;
for(int i=0;i<n;i++){
s=read(),f=1,t=0,tmp=0;
for(int j=0;j<cnt;j++){
if(s%a[j]==0){
while(s%a[j]==0) t++,s/=a[j];
if(b[j]*m2%t) tmp=max(tmp,b[j]*m2/t);
else tmp=max(tmp,b[j]*m2/t+1);
}
else f=0;
}
if(f) ans=min(ans,tmp);
}
if(ans==1<<30) ans=-2;
cout<<ans+1<<endl;
}