Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 16189 | Accepted: 4022 |
题意:求n的m次幂的所有因数的和对9901取余;
思路:各种数学方法:
1: 对A进行素因子分解得
2:A^B的所有约数之和为:
3: 求等比数列1+pi+pi^2+pi^3+...+pi^n可以由递归形式的二分求得:(模运算不能用等比数列和公式!)
Description
Input
Output
Sample Input
2 3
Sample Output
15
Hint
The natural divisors of 8 are: 1,2,4,8. Their sum is 15.
15 modulo 9901 is 15 (that should be output).
Source
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<cctype>
#include<map>
#include<set>
#include<vector>
#define LL long long
using namespace std;
const int MOD= 9901;
LL pow(LL u,LL n)
{
LL ans=1;
while(n)
{
if(n&1)
ans=(ans*u)%MOD;
u=(u*u)%MOD;
n>>=1;
}
return ans;
}
LL sum(LL u,LL n)
{
if(n==0)
return 1;
if(n&1)
return ( (1+pow(u,n/2+1))*sum(u,n/2))%MOD;
else
return((1+pow(u,n/2+1))*sum(u,n/2-1)+pow(u,n/2))%MOD;
}
int main()
{
LL n,m;
LL ans;
while(~scanf("%lld%lld",&n,&m))
{
ans=1;
LL u,v;
for(LL i=2;i*i<=n;i++)
{
v=0;
while(n%i==0)
{
v++;
n/=i;
}
ans=(ans*sum(i,v*m))%MOD;
}
if(n!=1)
ans=(ans*sum(n,m))%MOD;
printf("%lld\n",ans);
}
return 0;
}