'commit'
This commit is contained in:
49
TangDou/AcWing_TiGao/T6/DiTuiDiGui/97_QiuHeGongShi.cpp
Normal file
49
TangDou/AcWing_TiGao/T6/DiTuiDiGui/97_QiuHeGongShi.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user