多学习。

【约数定理】AcWing871.约数之和

AcWing871.约数之和

题解

约数定理

#include <iostream>
#include <cmath>
#include <unordered_map>

using namespace std;

const int MOD = 1e9 + 7;

typedef long long LL;

int main()
{
    unordered_map<int, int> primes;
    int n, x;
    cin >> n;
    while(n--)
    {
        cin >> x;
        for(int i = 2; i <= x/i; ++i)
        {
            while(x % i == 0)
            {
                primes[i] ++;
                x /= i;
            }
        }
        if(x > 1) primes[x] ++ ;
    }
    LL res = 1, tmp, a;
    for(auto t: primes)
    {
        tmp = a = 1;
        for(int i = 1; i <= t.second; ++i)
            a = (a * t.first) % MOD, tmp = (tmp + a) % MOD;
        res = (res * tmp) % MOD;
    }
    cout << res << endl;
    return 0;
}
posted @ 2022-06-02 20:26  czyaaa  阅读(41)  评论(0)    收藏  举报