关于约数(划重点)
如果 N = p1^c1 * p2^c2 * ... *pk^ck
约数个数: (c1 + 1) * (c2 + 1) * ... * (ck + 1)
约数之和: (p1^0 + p1^1 + ... + p1^c1) * ... * (pk^0 + pk^1 + ... + pk^ck)
关于取模
(a + b) % p = (a%p + b%p) %p
(a - b) % p = (a%p - b%p) %p
(a * b) % p = (a%p * b%p) %p
870.题目
给定n个正整数ai,请你输出这些数的乘积的约数个数,答案对+7取模。
输入格式
第一行包含整数n。
接下来n行,每行包含一个整数ai。
输出格式
输出一个整数,表示所给正整数的乘积的约数个数,答案需对+7取模。
数据范围
1≤n≤100,
1≤ai≤2∗
输入样例
3
2
6
8
输出样例
12
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod=1e9+7;
int main()
{
int n,x;
LL ans=1;
unodered_map<int,int>hash;
cin>>n;
while(n--)
{
cin>>x;
for(int i=2;i<=x;i++)
{
while(x%i==0)
{
x/=i;
hash[i]++;
}
}
if(x>1)hash[x]++;
}
for(auto i:hash) ans=ans*(i.second+1)%mod;
cout<<ans;
return 0;
}
(题目分割线~)
871.题目
给定n个正整数ai,请你输出这些数的乘积的约数之和,答案对+7取模。
输入格式
第一行包含整数n。
接下来n行,每行包含一个整数ai。
输出格式
输出一个整数,表示所给正整数的乘积的约数之和,答案需对+7取模。
数据范围
1≤n≤100,
1≤ai≤2∗
输入样例
3
2
6
8
输出样例
252
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod=1e9+7;
int main()
{
int n,x;
LL res=1;
unordered_map<int,int>hash;
cin>>n;
while(n--)
{
cin>>x;
for(int i=2;i<=x;i++)
{
while(x%i==0)
{
x/=i;
hash[i]++;
}
}
if(x>1) hash[x]++;
}
for(auto i:hash)
{
int a=i.first,b=i.second;
int t=1;
while(b--) t=(1+a*t)%mod;
res=res*t%mod;
}
cout<<res<<endl;
return 0;
}