RE 1个点 心态炸了,求助

P1593 因子和

愚末语tenseTL @ 2021-03-06 18:57:28

#include<bits/stdc++.h>
using namespace std;
#define pub push_back
#define pob pop_back
#define in insert
#define er erase
#define ll long long
#define mod 9901
const int MAXN=1e7+5;
int primes[MAXN];
int num[MAXN];
set<int >v;
int b;
void prepare()
{
    int j=-1;
    for(int i=2;i<=100000;i++)
    {
        if(primes[i]==0)primes[++j]=i;
        for(int t=0;t<=j&&i*primes[t]<=100000;t++)
        {
            primes[i*primes[t]]=1;
            if(i%primes[t]==0)break;
        }
    }
}
ll quickmod(ll a,ll b1)
{
    ll kase=1;
    while(b1)
    {
        if(b1&1)kase=kase*a%mod;
        a=a*a%mod;
        b1>>=1;
    }
    return kase;
}
void findit(int t)
{
    int m=t;
    for(int i=0;primes[i]*primes[i]<=t;i++)
    {
        if(m%primes[i]==0)
        {
            int number=0;
            v.in(primes[i]);
            while(m%primes[i]==0)m/=primes[i],number++;
            num[primes[i]]=number*b;
        }
        if(m==1)break;
    }
    if(m>1)v.in(m),num[m]=b;
}
ll ni(ll x)
{
    return quickmod(x,mod-2)%mod;
}
ll findsum(int p,int n)
{
    ll kase=(quickmod(p,n)-1)%mod;
    if((p-1)%mod==0)return n;//mod 9901 可能逆元不存在  
    else 
    return kase= (kase*ni(p-1)%mod+mod)%mod;
}
void solve()
{
    ll kase=1;
    for(auto it=v.begin();it!=v.end();it++)
    {
        ll t=findsum((*it),num[*it]+1);
        if(t==0)continue;
        else 
        kase=kase*findsum((*it),num[*it]+1)%mod;

    }
    cout<<kase<<endl;
}
int main()
{
    prepare();
    int a;
    cin>>a>>b;
    if(a==1){cout<<1<<endl;return 0;}
    findit(a);
    solve();
    return 0;
 } 

by JJA_ @ 2021-03-07 22:32:35

@愚末语tenseTL 您MAXN开小了,不是 1e7+5 而是 1e7*5


|