P1069 细胞分裂
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int N=1e4+5; int n,m1,m2; int s[N],prime[N],maxn,t=2,c,ans=0x7fffffff,l; int main() { scanf("%d%d%d",&n,&m1,&m2); for(int i=1;i<=n;++i) scanf("%d",s+i); if(m1==1) { printf("0"); return 0; } while(m1!=1) { while(m1%t==0) m1/=t,++prime[t]; maxn=max(maxn,t); prime[t++]*=m2; //a的幂乘以a的幂'=a的(幂+幂')次方 } for(int i=1;i<=n;++i) { l=0; for(int j=2;j<=maxn;++j) { if(!prime[j]) continue; c=0; while(s[i]%j==0) s[i]/=j,++c; if(!c) { l=0x7fffffff; break; } l=max(l,(prime[j]-1)/c); //次数 } ans=min(ans,l); } printf("%d",ans==0x7fffffff?-1:ans+1); return 0; }