You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 9901;
int A, B;
//分解质因数
map<int, int> primes; // map存的是数对key+value,默认按key由小到大排序
void divide(int x) {
for (int i = 2; i <= x / i; i++)
while (x % i == 0) primes[i]++, x /= i;
if (x > 1) primes[x]++;
}
//快速幂
int qmi(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = (LL)res * a % mod;
a = (LL)a * a % mod;
b >>= 1;
}
return res;
}
int main() {
scanf("%d %d", &A, &B);
//对A分解质因子
divide(A);
int res = 1;
for (auto it : primes) {
// p是质因子k是质因子的次数
int p = it.first, k = it.second * B;
// res要乘上每一项, 注意这里是k + 1
if ((p - 1) % mod == 0) {
//不存在逆元由于p-1的是mod的倍数, 故p%mod=1
//所以1 + p + ... + p^k每个数%mod都是1共k + 1个数总就是k + 1
res = (LL)res * (k + 1) % mod;
} else
//分子用快速幂计算注意标准公式和此题的区别k+1
//分母用费马小定理求逆元 qmi(p-1,mod-2)
res = (LL)res * (qmi(p, k + 1) - 1) % mod * qmi(p - 1, mod - 2) % mod;
}
if (!A) res = 0;
printf("%d\n", (res % mod + mod) % mod);
return 0;
}