求約數之和

一個數 N 的約數個數:
設 N = p1^a1 * p2 ^ a2 * p3 ^ a3 … pn ^ an;
約數個數 sum = (a1 + 1) * (a2 + 1) * ***** ( an + 1).
約數之和: (p1^0 + p1 ^ 1 + … p1^a1) * (p2^0 + p2 ^ 1 + …p2^a2) …

求幾個數的乘積的約數之和

#include <iostream>
#include <cstring>
#include <unordered_map>
#include <algorithm>
using namespace std;
const int mod = 1e9 + 7;
int n;
long long ans = 1;
unordered_map<int, int> m;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    while (n--)
    {
        int x;
        cin >> x;
        for (int i = 2; i <= x / i; i++)
        {
            while (x % i == 0)
            {
                x /= i;
                m[i]++;
            }
        }
        if (x > 1)
            m[x]++;
    }
    for (unordered_map<int, int>::iterator it = m.begin(); it != m.end(); it++)
    {
        int p = it->first;
        int k = it->second;
        long long t = 1;
        while (k--)
            t = (t * p + 1) % mod;
        ans = (ans * t) % mod;
    }
    cout << ans << endl;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章