40分求助

P1593 因子和

_wakeup @ 2024-07-07 10:15:59

rt

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#define ll long long
#define INF 2147483647
#define P 998244353
using namespace std;
ll a,b,m=0,p[50],c[50],ans=1,mod=9901;
void cha(ll n)
{
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            p[++m]=i,c[m]=1;
            while(n%i==0)n/=i,c[m]++;
        }
    }
    if(n>1)p[++m]=n,c[m]=1;
}
int mi(ll a,ll b)
{
    ll x=b,t=a,num=1;
    while(x)
    {
        if(x&1)num=(num*t)%mod;
        t=(t*t)%mod;
        x>>=1;
    }
    return num;
}
int main()
{
    cin>>a>>b;
    cha(a);
    for(int i=1;i<=m;i++)
    {
        if((p[i]-1)%mod==0)
        {
            ans=(b*c[i]+1)%mod*ans%mod;
            continue;
        }
        ll x=mi(p[i],b*c[i]+1),y=mi(p[i]-1,mod-2);
        x=(x-1+mod)%mod;
        ans=ans*x%mod*y%mod;
    }
    cout<<ans<<endl;
    return 0;
}

|