Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).
Input
The only line contains the two natural numbers A and B, (0 <= A,B <= 50000000)separated by blanks.
Output
The only line of the output will contain S modulo 9901.
Sample Input
2 3Sample Output
15Hint
2^3 = 8.
The natural divisors of 8 are: 1,2,4,8. Their sum is 15.
15 modulo 9901 is 15 (that should be output).
其实这道题kuangbin有模板,利用了约数和定理:f(n)=(p1^0+p1^1+p1^2+…p1^a1)(p2^0+p2^1+p2^2+…p2^a2)…(pk^0+pk^1+pk^2+…pk^ak)
#include<iostream>
#include<cstring>
#include<algorithm>
typedef long long ll;
using namespace std;
const int maxn=10000;
const int p=9901;
int prime[maxn+1];
void getprime()
{
memset(prime,0,sizeof(prime));
for(int i=2;i<=maxn;i++)
{
if(!prime[i])
prime[++prime[0]]=i;
for(int j=1;j<=prime[0]&&prime[j]<=maxn/i;j++)
{
prime[prime[j]*i]=1;
if(i%prime[j]==0)break;
}
}
}
ll factor[100][2];
int fatcnt;
int getfactors(ll x)
{
fatcnt=0;
ll temp=x;
for(int i=1;prime[i]<=temp/prime[i];i++)
{
factor[fatcnt][1]=0;
if(temp%prime[i]==0)
{
factor[fatcnt][0]=prime[i];
while(temp%prime[i]==0)
{
factor[fatcnt][1]++;
temp/=prime[i];
}
fatcnt++;
}
}
if(temp!=1)
{
factor[fatcnt][0]=temp;
factor[fatcnt++][1]=1;
}
return fatcnt;
}
ll pow_m(ll a,ll n)
{
ll ret=1;
ll temp=a%p;
while(n)
{
if(n&1)ret=(ret*temp)%p;
n>>=1;
temp=temp*temp;
temp%=p;
}
return ret;
}
ll sum(ll m,ll n)
{
if(m==0)return 0;
if(n==0)return 1;
if(n&1)
return ((1+pow_m(m,n/2+1))%p*sum(m,n/2)%p)%p;
else return ((1+pow_m(m,n/2+1))%p*sum(m,n/2-1)+pow_m(m,n/2)%p)%p;
}
ll solve(ll a,ll b)
{
getfactors(a);
ll ans=1;
for(int i=0;i<fatcnt;i++)
{
ans*=(sum(factor[i][0],b*factor[i][1])%p);
ans%=p;
}
return ans;
}
int main()
{
getprime();
ll a,b;
cin>>a>>b;
cout<<solve(a,b)<<endl;
}