思路:约数和定理
关于二分法:
Code:
#include <bits/stdc++.h>
#define mod 9901
#define rep(i,a,b) for (int i=a; i<=b; i++)
using namespace std;
int qpow (int a, int b) {
int ans = 1;
a %= mod;
while (b) {
if (b & 1) {
ans = ans * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return ans;
}
/** * getsum:求 1 + p + p^2 + p^3 + ... + p^k */
//版本1 奇数与偶数做相应的操作
int getsum (int p, int k) {
if (p == 0) return 0;
if (k == 0) return 1;
if (k & 1) return (qpow(p, (k >> 1) + 1) + 1) * getsum(p, k >> 1) % mod;
return ( (qpow(p, (k >> 1) + 1) + 1) * getsum(p, (k >> 1) - 1) % mod + qpow(p, k >> 1) ) % mod;
}
//版本2 遇到偶数统统转为奇数项再操作
int getsum2 (int p, int k) {
if (p == 0) return 0;
if (k == 0) return 1;
if (k & 1) return (qpow(p, (k >> 1) + 1) + 1) * getsum2(p, k >> 1) % mod;
return (p % mod * getsum2(p, k - 1) + 1) % mod; //把奇数项和划归为求偶数项的子问题
}
int solve (int A, int B) {
int res = 1, k;
rep(i, 2, A) {
if (A % i == 0) {
k = 0;
while (A % i == 0) {
k++;
A /= i;
}
res = res * getsum2(i, k * B) % mod;
}
}
if (A == 0) res = 0;
return res;
}
int main() {
int A, B;
scanf("%d%d", &A, &B);
printf("%d\n", solve(A, B));
return 0;
}