跳到正文

题解

题解:SP18202 HG - HUGE GCD

fish_love_cat约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
题目
SP18202

版本

  1. v1当前

更加困难的双倍经验:SP30755


从 gcd⁡\gcd 的定义入手的话这题是好想的,我们可以把两个数字分别分解质因数,然后取重合部分的乘积即为答案。

于是对于每一个因子分解质因数存起来,然后指数取最小就行了。

然后我是奶龙,我以为这题会卡常规分解质因数写法,于是写了个 Pollard-rho /qd

当然也能过就是了。

警惕输出有坑,可能需要补前导零而非单纯取模!

C++
// pr 一大坨就不放了
map<int,int>ans;
int ret=1;
map<int,int>qvq;
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    int n;n=2;
    // cin>>n;
    for(int i=1;i<=n;i++){
        map<int,int>awa;
        int m;
        cin>>m;
        while(m--){
            int x;
            cin>>x;
            while(x!=1){
                int flc=Po(x);
                awa[flc]++;
                x/=flc;
            }
        }
        for(auto j:awa){
            if(qvq[j.first]!=i-1)continue;
            if(i!=1)ans[j.first]=min(j.second,ans[j.first]);
            else ans[j.first]=j.second;
            qvq[j.first]=i;
        }
    }
    for(auto i:ans)
    if(qvq[i.first]==n)
        ret=(ret*qpow(i.first,i.second,mod)),flag|=ret>mod,ret%=mod;
    if(flag)printf("%09lld",ret);// 并非单纯取模!
    else cout<<ret;
    return 0;
}

Accepted.

原文