WA 11,12,13点,求调

P1593 因子和

wanttoac @ 2024-05-28 20:44:26

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 50000007
#define MOD 9901
bool isprime[MAXN]; 
int prime[MAXN]; 
int n=MAXN; 
int cnt;
int p[MAXN];
void init()
{
    memset(isprime, true, sizeof(isprime)); 
    isprime[1] = false; 
    for (int i = 2; i <= n; ++i)
    {
        if (isprime[i]) prime[++cnt] = i;

        for (int j = 1; j <= cnt && i * prime[j] <= n; ++j)
        {
            isprime[i * prime[j]] = false;

            if (i % prime[j] == 0) break;
        }
    }
}
int quick(int a,int b){
    int res=1;
    while(b){
        if(b&1){
            res=(res*a+MOD)%MOD;
            b--;
        }
        else{
            a=(a*a+MOD)%MOD;
            b>>=1;
        }
    }
    return res;
}
int solve(int x){
    return quick(x,MOD-2);
}
signed main(){
    init();
    int a,b,count=0;
    cin>>a>>b;
    for(int i=1;i<=cnt&&a!=1;i++){
        int cntt=0;
        while(a%prime[i]==0){
            a/=prime[i];
            cntt++;
        }
        p[i]=cntt;
        count++;
    }
    int res=1;
    for(int i=1;i<=count;i++){
        res=res*(quick(prime[i],p[i]*b+1)-1+MOD)%MOD;
        res=res*solve(prime[i]-1+MOD)%MOD;
    }
    cout<<res<<endl;
}

|