求救!!!!WA了第十三个点,凑不出HACK数据> <

P1593 因子和

csq_pig @ 2024-01-19 21:35:42

大佬求调!

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=9901;
bool is_prime[100010];
ll prime[100010],t;
ll p[100010],s[100010],k,ans=1;
ll fast (ll a,ll q)
{
    ll k=a,s=1;
    while (q) {
        if (q&1) s=s*k%MOD;
        k=k*k%MOD;
        q>>=1;
    }
    return s%MOD;
}
ll a,b;
int main()
{
    scanf("%lld%lld",&a,&b);
    for (ll i=1;i<=100000;i++) is_prime[i]=true;
    for (ll i=2;i<=100000;i++) {
        if (is_prime[i]) prime[++t]=i;
        for (ll j=1;j<=t && prime[j]*i<=100000;j++) {
            is_prime[prime[j]*i]=false;
            if (i%prime[j]==0) break;
        }
    }
    for (ll i=1;i<=t;i++) {
        if (a%prime[i]==0)
            p[++k]=prime[i];
        while (a%prime[i]==0) {
            a/=prime[i];
            s[k]++;
        }
    }
    for (ll i=1;i<=k;i++) s[i]*=b;
    for (ll i=1;i<=k;i++) {
        if (p[i]%MOD==1 && p[i]!=1) {
            ans=ans+s[i]+1;
            ans%=MOD;
            continue;
        }
        ans=ans*(fast(p[i],s[i]+1)-1)%MOD;
        ans=ans*(fast(p[i]-1,MOD-2))%MOD;
    }
    if (a!=1) ans=ans*(1+a)%MOD;
    printf("%lld",(ans+MOD)%MOD);
    return 0;
}

by csq_pig @ 2024-01-19 22:04:22

已AC,感谢奆佬帮忙发现bug,我是**


|