《超时》
2025-05-26 16:39:29
发布于:浙江
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
const int maxn=30005;
int n,m1,m2,minn=1e9;
int prime[maxn]={0};
bool flag=false,here;
int pipe_prime[maxn];
int cell_prime[maxn];
int sum_prime=0,cell;
bool pr(int k){
for(int i=2;i*i<=k;i++){
if(k%i==0)return false;
}
return true;
}
int main(){
cin>>n;
cin>>m1>>m2;
for(int i=2;i<=maxn;i++){
if(pr(i)){
sum_prime++;
prime[sum_prime]=i;
}
}
int idx=1;
while(m1!=1){
if(m1%prime[idx]==0)
while(m1%prime[idx]==0){
pipe_prime[idx]+=m2; m1/=prime[idx];
}
idx++;
}
for(int i=1;i<=n;i++){
cin>>cell;
int j=1;
int now=0;
here=true;
memset(cell_prime,0,sizeof(cell_prime));
while(j<=sum_prime){
if(cell%prime[j]==0){
while(cell%prime[j]==0){
cell_prime[j]; cell/=prime[j];
}
}
j;
}
for(j=1;j<=sum_prime;j++){
if(pipe_prime[j]!=0&&cell_prime[j]==0)here=false;
if(pipe_prime[j]!=0&&cell_prime[j]!=0){
if(pipe_prime[j]%cell_prime[j]==0)
now=max(now,pipe_prime[j]/cell_prime[j]);
else now=max(now,pipe_prime[j]/cell_prime[j]+1);
}
}
if(here){
flag=true;
if(now<minn)minn=now;
}
}
if(flag)cout<<minn;
else cout<<-1;
}
这里空空如也
有帮助,赞一个