竞赛讨论区 > I题直接分解为什么不对
头像
letyougo
发布于 2023-08-23 17:09
+ 关注

I题直接分解为什么不对

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);cout.tie(nullptr);
    
    int n;cin>>n;
    int a,b;cin>>a>>b;
    if(a==1){
        cout<<0<<endl;
        return 0;
    }
    vector<pair<int,int>> tip;
    for(int i=2;i*i<=a;i++){
        if(a%i==0){
            int now=0;
            while(a%i==0){
                now++;
                a/=i;
            }
            tip.push_back({i,now*b});
        }
    }
    if(a>1){
        tip.push_back({a,b});
    }
    
    int x,ans=1e18;
    for(int i=1;i<=n;i++){
        cin>>x;
        int o=1,f=1;
        for(auto [m,k]:tip){
            int xx=x;
            if(xx%m){f=0;break;}
            int now=0;
            while(xx%m==0){
                xx/=m;
                now++;
            }
            o=max(o,k/now+(k%now!=0));
        }
        if(f){
            ans=min(ans,o);
        }
    }
    if(ans>1e17){
        cout<<-1<<endl;
    }
    else{
        cout<<ans<<endl;
    }
}

全部评论

(1) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐