题意:给出A,B,求A^B的所有约数之和
思路:首先给A分解质因数,若A = C1 ^ e1 * ... * Cn ^ en,则A ^ B = C1 ^ (e1 * B) * ... * Cn ^ (en * B),
容易知道,其所有约数之和为:
Ans = [C1 ^ 0 + C1 ^ 1 + ... + C1 ^ (e1 * B)] * [C2 ^ 0 + ... + C2 ^ (e2 * B)] * ... * [Cn ^ 0 + ... + Cn ^ (en * B)]
每一个因式都是一个等比数列,二分即可
代码:
#include <cstdio>
const int Mod = 9901;
typedef long long LL;
LL Powmod(LL x, LL exp){
LL s = 1;
while(exp){
if(exp & 1)s = s * x % Mod;
x = x * x % Mod;
exp >>= 1;
}
return s;
}
LL c[Mod], e[Mod], cnt, A, B;
void GetFacts(LL n){
for(LL i = 2;i * i <= n;i ++)
if(n % i == 0){
n /= i, c[++cnt] = i, e[cnt] = 1;
while(n % i == 0) n /= i, e[cnt] ++;
}
if(n > 1)c[++cnt] = n, e[cnt] = 1;
}
LL solve(LL x, LL exp){
if(!exp)return 1;
LL s = solve(x, (exp - 1) >> 1) * (1 + Powmod(x, (exp + 1) >> 1)) % Mod;
if(exp % 2 == 0) s = (s + Powmod(x, exp)) % Mod;
return s;
}
int main(){
scanf("%lld%lld", &A, &B);
if(!A){
puts("0");return 0;
}
GetFacts(A);
LL Ans = 1;
for(int i = 1;i <= cnt; i++)
Ans = Ans * solve(c[i], e[i] * B) % Mod;
printf("%lld\n", Ans);
return 0;
}