Pagini recente » Cod sursa (job #2029551) | Cod sursa (job #1089136) | Cod sursa (job #2830600) | Cod sursa (job #2191780) | Cod sursa (job #484052)
Cod sursa(job #484052)
#include<iostream>
#include<cstring>
#include<fstream>
using namespace std;
const int P=9901;
const int lim=7200;
int primes[lim],cnt=0;
void gcd(int a,int b,int& x,int& y)
{
if(b==0)
{
x=1;
y=0;
}
else
{
gcd(b,a%b,x,y);
int aux=x;
x=y;
y=aux-(a/b)*y;
}
}
int inv_modular(int a,int p)
{
int x,y;
gcd(a,p,x,y);
if(x<=0)
x=p+x%p;
return x;
}
void ciur()
{
int v[lim];
memset(v,0,sizeof(v));
for(int i=2;i<lim;i++)
if(v[i]==0)
{
for(int j=i+i;j<lim;j+=i)
v[j]=1;
primes[cnt++]=i;
}
}
int pow(int a,int b,int mod)
{
if(b==1)
return (a%mod);
if(b%2==0)
{
int x=pow(a,b/2,mod);
int rez=x*x;
return rez%mod;
}
else
{
int x=pow(a,b/2,mod);
int rez=x*x;
rez%=mod;
rez*=a;
rez%=mod;
return rez;
}
}
int solve(int A,int B,int mod)
{
int p=1;
ciur();
int putere=0;
for(int i=0;i<cnt;i++)
{
putere=0;
while(A%primes[i]==0)
{
++putere;
A/=primes[i];
}
if(putere>0)
{
int pr=putere*B+1;
p*=((pow(primes[i],pr,mod)-1)*inv_modular(primes[i]-1,mod))%mod;
p%=mod;
}
if(A==1)
break;
}
if(A>1)
{
if(A%mod==1)
{
p=p*(B+1);
p%=mod;
}
else
{
p*=((pow(A,B+1,mod)-1)*inv_modular(A-1,mod))%mod;
p%=mod;
}
}
return p;
}
int main()
{
int A,B;
ifstream in("sumdiv.in");
in>>A>>B;
in.close();
ofstream out("sumdiv.out");
out<<solve(A,B,P)<<endl;
out.close();
}