洛谷P1593 因子和
\(\large{题目链接}\)
\(\\\)
\(\Large\textbf{Solution: } \large{ 易证一个数N的所有因子和为:\left( 1+p^{1}_{1}+p^{2},+\ldots +p_{1} ^{c_{1}}\right) + \ldots + \left( 1+p^{1}_{n}+p^{2}_{n}+\ldots +p^{c_m}_{n}\right)=\prod \limits ^{m}_{i=1}( \sum \limits ^{c_{i}}_{j=0}\left( p_{i}\right) ^{j}。\\然后如果用费马小定理求逆元的话,注意p_i \mod p如果为1,要特判,因为费马小定理只满足p_i - 1与p互质,然后鬼知道我为什么93。\\注意特判a=0。}\)
\(\\\)
\(\Large\textbf{Code: }\)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int p = 9901;
int sol(int x, int y) {
ll a = x % p, ret = 1; ++y;
for (; y ; a = (a * a) % p, y >>= 1) if (y & 1) ret = (ret * a) % p;
a = (x - 1) % p, y = p - 2, --ret;
ll s = 1;
for (; y ; a = (a * a) % p, y >>= 1) if (y & 1) s = (s * a) % p;
return (ret * s) % p;
}
int main() {
ios::sync_with_stdio(false);
int a, b;
cin >> a >> b;
int t = sqrt(a); ll ans = 1;
for (int i = 2; i <= t; ++i) {
if (a % i) continue;
int cnt = 0;
while (!(a % i)) { ++cnt, a /= i; }
if (i % p == 1) ans = ans * (cnt + 1) % p;
else ans = ans * 1ll * sol(i, cnt * b) % p;
}
if (a != 1)
if (a % p == 1) ans = ans * (b + 1) % p;
else ans = ans * 1ll * sol(a % p, b) % p;
printf("%d\n", ans);
return 0;
}