AcWing 871. 约数之和
原题链接
简单
作者:
wugensheng
,
2021-04-12 22:27:36
,
所有人可见
,
阅读 205
试除法求约数和
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int M = 1e9 + 7;
map<int, int> mmap;
void divide(int x) { // 试除法求x的所有质数及其指数
for (int i = 2; i <= x / i; i++) {
if (x % i == 0) {
int cnt = 0;
while (x % i == 0) x /= i, cnt++;
mmap[i] += cnt;
}
}
if (x > 1) mmap[x] += 1;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
divide(x);
}
long long ans = 1;
for (auto t : mmap) {
long long a = t.first, b = t.second;
long long tmp = 1;
while (b--) tmp = (tmp * a + 1) % M;
ans = ans * tmp % M;
}
cout << ans << endl;
return 0;
}