https://www.luogu.com.cn/discuss/new?forum=academics
题意:求 AB 的约数之和模 9901
今天看到这题,以为很简单,结果发现模数很小,怎么办?以为求分子和分母分别有多少模数的因子个数就行了,但还是寄了。
代码求调:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int P=9901;
int x,y,z,ans,fz,fm;
map<int,int>mp;
inline int fpm(int x,int y){
int res=1;
for(;y;y>>=1,(x*=x)%=P)
if(y&1)(res*=x)%=P;
return res;
}
signed main(){
cin>>x>>y;if(!x)cout<<0,exit(0);
for(int i=2; i*i<=x; ++i)
while(x%i==0)x/=i,++mp[i];
if(x>1)++mp[x];ans=1;
for(auto it=mp.begin(); it!=mp.end(); ++it){
int x=it->first,xm=(it->second)*y+1;
int y=it->first-1,ym=P-2,xx=fpm(x,xm)+P-1;
while(xx%P==0)++fz,xx/=P;
while(y%P==0)fm+=ym,y/=P;
(ans*=xx%P*fpm(y,ym)%P)%=P;
}if(fz>fm)cout<<0;else cout<<ans;
}