https://www.luogu.org/problem/show?pid=1069#sub
普及第三题咳咳咳咳
其实主要就是质因数分解
for(int i=2;i*i<=m1;i++)
if(m1%i==0){
a[++top]=i;
while(m1%i==0)b[top]++,m1/=i;
}
if(m1>1)a[++top]=m1,b[top]=1;
据说这个不是最快的;
然后就是m1^m2次方分解质因数;
所以我们对于读入,只需要一个个取满足m1^m2的质因数就好了;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define Ll long long
using namespace std;
int a[30000],top,b[30000],d[30000];
int n,m1,m2,x,y,ans=1e9;
int work(int x){
for(int i=1;i<=top;i++){
d[i]=0;
while(x%a[i]==0)d[i]++,x/=a[i];
}
int ans=0;
for(int i=1;i<=top;i++){
if(d[i]==0)return 1e9;
int k=b[i]/d[i];
if(k*d[i]<b[i])k++;
ans=max(ans,k);
}
return ans;
}
int main()
{
scanf("%d%d%d",&n,&m1,&m2);
for(int i=2;i*i<=m1;i++)
if(m1%i==0){
a[++top]=i;
while(m1%i==0)b[top]++,m1/=i;
}
if(m1>1)a[++top]=m1,b[top]=1;
for(int i=1;i<=top;i++)b[i]*=m2;
for(int i=1;i<=n;i++){
scanf("%d",&x);
ans=min(ans,work(x));
}
if(ans==1e9)printf("-1");else printf("%d",ans);
}