只过了#1,#5,#7,#8,求救
查看原帖
只过了#1,#5,#7,#8,求救
903392
T7_Daniel楼主2024/10/17 16:45

有注释,马蜂良好

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N=30005;
int p[N],tot;
int cnt_m[N],cnt_now[N];//cnt_m存储m1^m2,cnt_now存储s[i]

inline bool check(int x){//检查x是否是质数
    if(x<2) return 0;
    for(int i=2;i*i<=x;i++){
        if(x%i==0) return 0;
    }
    return 1;
}

inline void pre(){
    for(int i=1;i<=30000;i++){//求出每一个质数
        if(check(i)) p[++tot]=i;
    }
}

inline int read(){
    int s=0,f=1;
    char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        s=(s<<3)+(s<<1)+(ch-'0');
        ch=getchar();
    }
    return s*f;
}

signed main(){
    pre();
    int n;cin>>n;
    int m1=read(),m2=read();
    //分解m1,求出其质因数分解
	for(int i=1;i<=tot;i++){
        while(m1%p[i]==0){
            m1/=p[i];
            cnt_m[i]++;//第i个质数的出现次数+1
        }
    }
    for(int i=1;i<=tot;i++) cnt_m[i]*=m2;
    //Step 2:处理每个点
    int minn=2e9;
    while(n--){//共有n个数
        int now=read();
        //分解now
        for(int i=1;i<=tot;i++){
            while(now%p[i]==0){
                now/=p[i];
                cnt_now[i]++;//第i个质数的出现次数+1
            }
        }
        //现在,对应每一个数
        bool flag=1;//都能对应,默认为1
        int maxn=0;
        for(int i=1;i<=tot;i++){
            if(cnt_m[i]){//如果当前点m1^m2有
                if(cnt_now[i]==0){//无法对应
                    flag=0;
                    break;
                }
                //需要cnt_m[i]个,每一秒有cnt_now[i]个
                int tmp=cnt_m[i]/cnt_now[i];
                if((cnt_m[i]%cnt_now[i])!=0) tmp++;
                maxn=max(maxn,tmp);
            }
        }
        if(flag==0) continue;
        minn=min(minn,maxn);
        memset(cnt_now,0,sizeof cnt_now);
        //记得清空
    }
    if(minn!=2e9) cout<<minn;
    else cout<<-1;
    return 0;
}
/*
现在有 n 个数,每个数每过一秒就会*=si,求出最短的时间使得其是m1^m2的倍数
一共有多个数,求出最小值即可
m1^m2=30000^10000

分解质因数,去凑每一个数,因为数并不多,所以是最坏复杂度是O(pn),p是1~30000的质数个数
*/
2024/10/17 16:45
加载中...