Number of divisors / sum of divisors --------------- Number Theory (Unique Decomposition)

Given n positive integers ai, please output the approximate number of the product of these numbers, and the answer is modulo 109 + 7.

Input format The
first line contains the integer n.

Next n lines, each line contains an integer ai.

Output format
An integer is output, which represents the approximate number of products of positive integers given, and the answer needs to be modulo 109 + 7.

Data range
1≤n≤100,
1≤ai≤2 ∗ 109
Input sample:
3
2
6
8
Output sample:
12

Analysis:
unique decomposition theorem

Time complexity: O (sqrt (N))
Insert picture description here
Find the sum of divisors
Insert picture description here
Find the sum of divisorsInsert picture description here

#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
const int N=1e6+100;
#define x first
#define y second
typedef long long ll;
map<int,int>prime;
int t,x;
int main()
{
    cin>>t;
    for(int j=1;j<=t;j++)
    {
        scanf("%d",&x);
        for(int i=2;i<=x/i;i++)
        {
          
                while(x%i==0)
                {
                    x/=i;
                    prime[i]++;
                }
              
            
        } 
        if(x>1) prime[x]++;
    }
    ll res=1;
    for(auto  it : prime)
    {
        res=res*(it.y+1)%MOD;
    }
    cout<<res<<endl;
}

Given n positive integers ai, please output the sum of the divisors of the products of these numbers. The answer is modulo 109 + 7.

Input format The
first line contains the integer n.

Next n lines, each line contains an integer ai.

Output format
Output an integer that represents the sum of the divisors of the product of positive integers given. The answer needs to be modulo 109 + 7.

Data range
1≤n≤100,
1≤ai≤2 ∗ 109
Input sample:
3
2
6
8
Output sample:
252

Analysis:
sum of divisors
Insert picture description here


#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
const int N=1e6+100;
#define x first
#define y second
typedef long long ll;
map<int,int>prime;
int t,x;
int main()
{
    cin>>t;
    for(int j=1;j<=t;j++)
    {
        scanf("%d",&x);
        for(int i=2;i<=x/i;i++)
        {
          
                while(x%i==0)
                {
                    x/=i;
                    prime[i]++;
                }
              
            
        } 
        if(x>1) prime[x]++;
    }
    ll res=1;
    for(auto  it : prime)
    {
        int b=it.y;
        ll ans=1;
        while(b--) ans=(ans*it.x+1)%MOD;
        res=res*ans%MOD;
    }
    cout<<res<<endl;
}
Published 572 original articles · praised 14 · 10,000+ views

Guess you like

Origin blog.csdn.net/qq_43690454/article/details/105200242