AcWing 871. 约数之和
原题链接
简单
作者:
紫枫家的非鱼
,
2025-01-15 19:42:14
,
所有人可见
,
阅读 1
#include <iostream>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define int long long
#define js \
ios::sync_with_stdio(false); \
cin.tie(nullptr);
const int N = 1e6 + 5, MOD = 1e9 + 7;
unordered_map<int, int> p;
int ksm(int d, int mi)
{
int res = 1;
while (mi)
{
if (mi & 1)
res = res * d % MOD;
d = d * d % MOD;
mi >>= 1;
}
return res;
}
void f(int x, int& n)
{
while (n % x == 0)
p[x]++, n /= x;
}
void solve(int n)
{
if (n == 1)
return;
f(2, n), f(3, n);
for (int i = 5; i * i <= n; i += 6)
f(i, n), f(i + 2, n);
if (n > 1)
f(n, n);
}
signed main()
{
js int t, n;
cin >> t;
for (int i = 0; i < t; i++)
{
cin >> n;
solve(n);
}
int a = 1, b = 1;
for (auto [d, mi] : p)
{
a = a * (ksm(d, mi + 1) - 1 + MOD) % MOD; // 这里注意
b = b * (d - 1) % MOD;
}
cout << a * ksm(b, MOD - 2) % MOD;
return 0;
}