思路见:三十四、数学知识——约数(试除法 + 约数个数 + 约数之和 + 欧几里得算法)-优快云博客
约数之和:
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
const int N=110,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 x:primes){
int p=x.first,a=x.second;
ll t=1;
while(a--)t=(t*p+1)%mod;
res=res*t%mod;
}
cout<<res<<endl;
}
约数个数:
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
const int N=110,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 p:primes)res=res*(p.second+1)%mod;
cout<<res<<endl;
}

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



