莫欺少年穷,修仙之旅在这开始—>算法基础课题解
思路:
$ N = \prod\limits_{i=1}^k p_i^{a_i}=p_1^{a_1}\cdot p_2^{a_2}… p_k^{a_k} $
$ 约数个数:\prod\limits_{i=1}^k(a_i+1)=(a_1+1)(a_2+1)…(a_k+1) $
$\begin{aligned}约数之和:\prod\limits_{i=1}^k \sum\limits_{j=0}^{a_i} p_i^j & = \prod\limits_{i=1}^k (p_i^0+p_i^1+…+p_i^{a_i}) \\\\ & = (p_1^0+p_1^1+…+p_1^{a_1})(p_2^0+p_2^1+…+p_2^{a_2})…(p_k^0+p_k^1+…+p_k^{a_k})\end{aligned}$
可参考: 约数个数
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9 + 7;
int main()
{
int n;
cin>>n;
unordered_map<int,int> primes;
while(n--)
{
int x;
cin>>x;
for(int i=2;i<=x/i;i++)
while(x%i==0)
{
x/=i;
primes[i]++;
}
if(x>1) primes[x]++;
}
LL res=1;
for(auto prime : primes)
{
int p=prime.first,a=prime.second;
LL t=1;
while(a--) t=(t*p+1)%mod;
res=res*t%mod;
}
cout<<res<<endl;
return 0;
}