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

51 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;
// 分解质因数
unordered_map<int, int> primes; // map存的是数对,key+value,默认按key由小到大排序
void divide(int x) {
for (int i = 2; i * i <= x; 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) { // 对b进行二进制分解(我给起的名),枚举b的每一个二进制位
if (b & 1) res = (LL)res * a % mod;
a = (LL)a * a % mod;
b >>= 1;
}
return res;
}
// 分治法求等比数列求和公式
int sum(int p, int k) {
if (k == 1) return 1; // 递归出口
if (k % 2 == 0) // 偶数
return (LL)(qmi(p, k / 2) + 1) * sum(p, k / 2) % mod;
return (qmi(p, k - 1) + sum(p, k - 1)) % mod; // 奇数
}
int main() {
cin >> A >> B;
// 对A分解质因子
divide(A);
int res = 1;
for (auto it : primes) {
// p是质因子,k是质因子的次数
int p = it.first, k = it.second * B; // 约数和公式,需要到每个质因子的it.second次方*B
// res要乘上每一项, 注意这里是k + 1
res = (LL)res * sum(p, k + 1) % mod; // 满满的套路感
}
if (!A) res = 0; // 还要特判A是不是0,注意思考数据边界
cout << res << endl;
return 0;
}