# poj1845 Sumdiv

Sumdiv
 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 23172 Accepted: 5769

Description

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 3

Sample Output

15

Hint

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).

Source

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

const int mod = 9901;
long long cnt[100010],wh[100010],tot,ans = 1;
int a,b;

void exgcd(long long a,long long b,long long &x,long long &y)
{
if (!b)
{
x = 1;
y = 0;
return;
}
exgcd(b,a % b,x,y);
long long t = x;
x = y;
y = t - (a / b) * y;
return;
}

long long qpow(long long a,long long b)
{
long long ans = 1;
while (b)
{
if (b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}

int main()
{
scanf("%d%d",&a,&b);
for (int i = 2; i <= sqrt(a); i++)
{
if (a % i == 0)
{
wh[++tot] = i;
while (a % i == 0)
{
a /= i;
cnt[i]++;
}
}
}
if (a)
{
wh[++tot] = a;
cnt[a]++;
}

for (int i = 1; i <= tot; i++)
{
long long x,y;
exgcd(wh[i] - 1,mod,x,y);
ans = (ans * (( qpow(wh[i],cnt[wh[i]] * b + 1) - 1)* x) % mod) % mod;
}
printf("%lld\n",ans);

return 0;
}


posted @ 2017-09-09 15:51 zbtrs 阅读(...) 评论(...) 编辑 收藏