Similar modulus as well as a relatively small pit that Lucas Theorem, and also the inverse would sometimes does not exist, except as a whole. By using some other method to avoid the inverse.
https://www.luogu.org/fe/problem/P1593
pit. You must be a good understanding of the conditions Fermat's little theorem inverse exist. Fermat's little theorem inversing the proviso that p is a prime number, and a is not 0, the Extended Euclidean Algorithm proviso that a, m coprime.
Then the above inversion yuan denominator geometric series with Fermat's Little Theorem, when there is no judge is not a zero. And they are not relatively prime so it can not use the extended Euclidean algorithm.
In fact, when a is reduced to 0 when the arithmetic sequence.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=9901;
ll a,b;
ll factor[100][2];
int ftop=0;
void fj() {
for(ll i=2; i*i<=a; i++) {
if(a%i==0) {
ftop++;
factor[ftop][0]=i;
factor[ftop][1]=0;
while(a%i==0) {
factor[ftop][1]++;
a/=i;
}
}
}
if(a!=1) {
ftop++;
factor[ftop][0]=a;
factor[ftop][1]=1;
}
for(int i=1; i<=ftop; i++) {
factor[i][1]*=b;
}
/*for(int i=1; i<=ftop; i++) {
printf("%lld %lld\n",factor[i][0],factor[i][1]);
}*/
}
ll da;
ll qpow(ll x,ll n) {
x%=mod;
ll res=1;
while(n) {
if(n&1) {
res*=x;
if(res>=mod)
res%=mod;
}
x*=x;
if(x>=mod)
x%=mod;
n>>=1;
}
if(res>=mod)
res%=mod;
return res;
}
void calc() {
ll pro=1;
for(int i=1; i<=ftop; i++) {
ll sum=0;
ll &p=factor[i][0];
ll &k=factor[i][1];
if((p-1)%mod==0) {
//退化为等差数列
sum=k+1;
} else {
sum=(qpow(p,k+1)-1+mod)%mod;
//printf("sum=%lld\n",sum);
sum*=qpow(p-1,mod-2);
}
if(sum>=mod)
sum%=mod;
//printf("sum=%lld\n",sum);
pro*=sum;
if(pro>=mod)
pro%=mod;
}
da=pro%mod;
}
int main() {
#ifdef Yinku
freopen("Yinku.in","r",stdin);
#endif // Yinku
scanf("%lld%lld",&a,&b);
if(a==0) {
printf("0\n");
return 0;
}
fj();
calc();
printf("%lld\n",da);
}