求约数个数
需要注意 = 的使用 ---- x=y+7 等价于x=x*(y+7)
res *= (iter.second + 1) % mod //这种写法的计算结果是不对的
C++ 代码
#include <iostream>
#include <cstring>
#include <unordered_map>
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 iter : primes) {
//cout << iter.first << " " << iter.second <<endl;
res = res * (iter.second + 1) % mod;
}
cout << res <<endl;
return 0;
}