Pagini recente » Cod sursa (job #469439) | Cod sursa (job #279695) | Cod sursa (job #2147471) | Cod sursa (job #56707) | Cod sursa (job #419155)
Cod sursa(job #419155)
#include<iostream>
#include<string>
using namespace std;
#define NM 1000005
#define MOD 9901
#define LL long long
char ciur[NM];
int primes[NM],dim;
void euclid(int a,int b,int &x,int &y)
{
if(!b)
{
x=1,y=0;
return ;
}
euclid(b,a%b,x,y);
int nx=y,ny=x-(a/b)*y;
x=nx,y=ny;
}
int invmod(int A,int N)
{
int x,y;
euclid(A,N,x,y);
while(x<0) x+=N;
return x;
}
LL power(LL A,LL p)
{
if(!p) return 1;
LL half=power(A,p/2);
LL ans=(half*half)%MOD;
if(p%2) ans=(ans*A)%MOD;
return ans;
}
int main()
{
LL q[100],k=0,A,B;
LL p[100];
freopen("sumdiv.in","r",stdin);
freopen("sumdiv.out","w",stdout);
for(int i=2;i<=1000000;++i)
if(!ciur[i])
{
primes[++dim]=i;
for(int j=2*i;j<=1000000;j+=i)
ciur[j]=1;
}
scanf("%lld %lld",&A,&B);
LL nr=A;
for(int i=1;i<=dim && nr>1;++i)
{
if((LL)primes[i]*primes[i]>A) break;
if(nr%primes[i]==0)
{
p[++k]=primes[i];
q[k]=0;
while(nr%primes[i]==0)
{
++q[k];
nr/=primes[i];
}
}
}
if(nr>1)
{
p[++k]=nr;
q[k]=1;
}
LL sum=1;
for(int i=1;i<=k;++i)
{
LL pq=power(p[i],q[i]*B+1);
pq--;
if(pq<0) pq+=MOD;
sum=(sum*pq)%MOD;
int invm=invmod(p[i]-1,MOD);
sum=(sum*invm)%MOD;
}
printf("%lld",sum);
return 0;
}