约数之和

题目描述

给定n个正整数ai,请你输出这些数的乘积的约数之和,答案对1e9+7取模。

输入

第一行包含整数n。

接下来n行,每行包含一个整数aiai

输出

输出一个整数,表示所给正整数的乘积的约数之和,答案需对1e9+7取模。

样例输入 Copy

3
2
6
8

样例输出 Copy

252

提示

1 ≤ n ≤ 100
1 ≤ ai ≤ 2e9
 

解释

例如24=8*3,那么24的约数之和就等于8的约数之和乘以3的约数之和
8 = 2^3,8的约数为1,2,4,8约数之和就为15,也可以这样算2^0 + 2^1 + 2^2 + 2^3 = (((2 + 1) * 2 + 1) * 2 + 1 = 15
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;

typedef long long LL;
const int N = 1e9 + 7;

int main()
{
    int n;
    cin >> n;

    unordered_map<LL, LL> arr;

    while (n --)
    {
        LL t;
        cin >> t;
        for (int i = 2; i <= t / i; )
        {
            if (t % i == 0)
            {
                t /= i;
                arr[i] ++;
                continue;
            }
            i++;
        }

        if (t > 1) arr[t] ++;
    }

    LL res = 1;
    for (auto i : arr)
    {
        LL t = 1;
        LL a = i.first, b = i.second;
        while (b--) t = (t * a + 1) % N;

        res = res * t % N;
    }

    cout << res << endl;

    return 0;
}

 

 

posted @ 2022-03-01 21:12  ora12321  阅读(18)  评论(0)    收藏  举报