当前位置:网站首页>Mathematical knowledge: sum of divisors - divisors

Mathematical knowledge: sum of divisors - divisors

2022-06-22 00:15:00 Fight! Sao Nian!

subject :AcWing 871. The sum of the approximations
Given n A positive integer ai, Please output the sum of divisors of the product of these numbers , The answer is right 109+7 modulus .

Input format
The first line contains integers n.

Next n That's ok , Each line contains an integer ai.

Output format
Output an integer , Represents the sum of divisors of the product of a given positive integer , The answer needs to be right 109+7 modulus .

Data range
1≤n≤100,
1≤ai≤2×109

sample input :

3
2
6
8

sample output :

252

Topic analysis :
If N=p1a1∗p2a2∗…∗pkak
Then sum of divisors : (p10+p11+…+p1a1)∗…∗(pk0+pk1+…+pkak)
If you find all of the p And The following code :
while (b -- ) t = (t * a + 1) % mod;
t=t∗p+1
t=1
t=p+1
t=p2+p+1
……
t=pb+pb−1+…+1

#include <iostream>
#include <unordered_map>

using namespace std;

const int mod = 1e9+7;

int main()
{
    
    unordered_map<int,int> primes;
    int n;
    cin>>n;
    while(n--)
    {
    
        int a;
        cin>>a;
        for(int i=2;i<=a/i;i++)
        {
    
            while(a%i==0)
            {
    
               primes[i]++;
               a/=i;
            }
        }
        if(a>1)primes[a]++;
    }
    
    long long res=1;
    for(auto it:primes)
    {
    
        long long mid = 1;
        int p=it.first,b=it.second;
        while(b--)mid=(mid*p+1)%mod;
        res=res*mid%mod;
    }
    cout<<res<<endl;
    return 0;
}
原网站

版权声明
本文为[Fight! Sao Nian!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206212226595997.html