AcWing 97. 约数之和(分治)
程序员文章站
2022-05-08 19:06:26
...
#include <bits/stdc++.h>
using namespace std;
const int mod = 9901;
int A, B;
int Qpow(int a, int b) {
a %= mod;
int ans = 1;
while (b) {
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
int solve(int p, int k) {
if (k == 0)
return 1;
if (k & 1)
return (1 + Qpow(p, (k + 1) / 2)) * solve(p, (k - 1) / 2) % mod;
else
return ((1 + Qpow(p, k / 2)) * solve(p, (k - 1) / 2) + Qpow(p, k)) % mod;
}
int main() {
//freopen("in", "r", stdin);
cin >> A >> B;
int res, ans = 1;
for (int i = 2; i <= A; i++) {
res = 0;
while (A % i == 0) {
res++;
A /= i;
}
if (res)
ans = ans * solve(i, res * B) % mod;
}
if (!A)
ans = 0;
cout << ans << endl;
return 0;
}
上一篇: eclipse 的maven安装