【jzoj5340】【NOIP2017模擬9.2A組】【春思】
阿新 • • 發佈:2019-02-14
description
solution
分解質因數然後等比數列求和,可能沒有逆元(本程式沒有處理這種情況),這時候需要特殊處理。
code
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LF double
#define LL long long
#define ULL unsigned int
#define fo(i,j,k) for(LL i=j;i<=k;i++)
#define fd(i,j,k) for(LL i=j;i>=k;i--)
#define fr(i,j) for(LL i=begin[j];i;i=next[i])
using namespace std;
LL const mn=1e6+9,mo=9901;
LL n,m,a[mn],b[mn];
LL Pow(LL x,LL y){
LL z=1;x%=mo;
while(y){
if(y&1)z=z*x%mo;
x=x*x%mo;
y>>=1;
}
return z;
}
int main(){
//freopen("spring.in","r",stdin);
//freopen ("spring.out","w",stdout);
freopen("d.in","r",stdin);
freopen("d.out","w",stdout);
scanf("%lld%lld",&n,&m);
LL lim=sqrt(n);
fo(i,2,lim)if(n%i==0){
a[++a[0]]=i;
while(n%i==0)b[a[0]]++,n/=i;
}
if(n!=1)a[++a[0]]=n,b[a[0]]=1;
LL ans=1;
fo(i,1,a[0])ans=ans*( Pow(a[i],b[i]*m+1)-1)%mo*Pow(a[i]-1,mo-2)%mo;
printf("%lld",(ans+mo)%mo);
return 0;
}