Files
python/TangDou/AcWing_TiGao/T6/DiTuiDiGui/97_QiuHeGongShi.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

49 lines
1.4 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}