AcWing871. 约数之和

题目链接:https://www.acwing.com/problem/content/description/873/

题目叙述:

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

输入格式

第一行包含整数 n。接下来 n行,每行包含一个整数 ai。

输出格式

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

数据范围

1≤n≤100,1≤ai≤2×10^9

输入样例:

3
2
6
8

输出样例:

252

直接上代码

#include<iostream>
#include<unordered_map>
using namespace std;
const int mod = 1e9 + 7;
int main()
{
	int n; cin >> n;
	//定义map容器存储所有的x的质因数的个数之和
	unordered_map<int, int> prime;
	while (n--) {
		int x; cin >> x;
		//找出x的所有质因数的个数
		for (int i = 2; i <= x / i; i++) {
			if (x % i == 0) {
				while (x % i == 0) {
					x /= i;
					prime[i]++;
				}
			}
		}
		if (x > 1) prime[x]++;
	}
	long long res = 1;
	for (auto p : prime) {
		int a = p.first;
		int b = p.second;
		long long t = 1;
		while (b--) t = (t * a + 1) % mod;
		res = res * t % mod;
	}
	cout << res;
	return 0;
}
posted @ 2024-07-24 11:34  Tomorrowland_D  阅读(1)  评论(0编辑  收藏  举报