给定 n 个正整数 ai,请你输出这些数的乘积的约数个数,答案对 109+7 取模。
输入格式
第一行包含整数 n。
接下来 n 行,每行包含一个整数 ai。
输出格式
输出一个整数,表示所给正整数的乘积的约数个数,答案需对 109+7 取模。
数据范围
1≤n≤100,
1≤ai≤2×109
输入样例:
3
2
6
8
输出样例:
12
公式:一个数的所有质因子为{P1,P2,P3,P4}
约数个数为(P1+1)*(P2+1)*(P3+1)*(P4+1)
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
unordered_map<int,int>vis;
int main()
{
int n,x;
cin>>n;
while(n--)
{
cin>>x;
for(int i =2;i<=x/i;i++)
{
if(x%i==0)
{
while(x%i==0)
{
vis[i]++;
x/=i;
}
}
}
if(x!=1)vis[x]++;
}
long long ans = 1;
for(auto it = vis.begin();it!=vis.end();it++)
{
ans = ans*(it->second+1)%mod;
}
cout<<ans<<endl;
return 0;
}
1万+



被折叠的 条评论
为什么被折叠?



