AcWing 870. 约数个数

题目传送门
参考阅读:约数个数与约数和专题

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
const int N = 110;
const int mod = 1e9 + 7;
//记录质数因子及个数
unordered_map<int, int> primes;
int n;

int main() {
    cin >> n;
    while (n--) {
        int x;
        cin >> x;
        for (int i = 2; i <= x / i; i++)
            while (x % i == 0) {
                x /= i;
                primes[i]++;
            }
        //如果还有大因子,那就加上
        if (x > 1) primes[x]++;
    }
    //公式
    LL res = 1;
    for (PII p: primes) res = res * (p.second + 1) % mod;
    //输出结果
    cout << res << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/littlehb/p/15341389.html