算法笔记.约数个数

题目:(acwing)

给定 n 个正整数 ai,请你输出这些数的乘积的约数个数,答案对 109+7 取模。

输入格式

第一行包含整数n。

接下来 n 行,每行包含一个整数 ai。

输出格式

输出一个整数,表示所给正整数的乘积的约数个数,答案需对 109+7 取模。

数据范围

1≤n≤100

1≤ai≤2×109

输入样例:
复制代码
3
2
6
8
输出样例:
复制代码
12

代码实现:

cpp 复制代码
#include<iostream>
#include<unordered_map>
using namespace std;
const int mod = 1e9+7;
int n;
unordered_map<int,int> primes;

void check(int x)
{
    int t = x;
    for(int i = 2;i <= x/i ;i++)
    {
        while(t%i == 0)
        {
           primes[i]++;
           t/=i;
        }
    }
    if(t > 1) primes[t]++;
}

int main()
{
    cin >>n;
    while(n--){
        int x;
        cin>>x;
        check(x);
    }
    long long res = 1;
    for(auto it = primes.begin();it!=primes.end();it++)
    {
        res= res*(it->second+1)%mod;
    }
    cout <<res;
    return 0;
}
相关推荐
海清河晏11136 分钟前
数据结构 | 单循环链表
数据结构·算法·链表
wuweijianlove5 小时前
算法性能的渐近与非渐近行为对比的技术4
算法
一定要AK5 小时前
Spring 入门核心笔记
java·笔记·spring
_dindong5 小时前
cf1091div2 C.Grid Covering(数论)
c++·算法
AI成长日志5 小时前
【Agentic RL】1.1 什么是Agentic RL:从传统RL到智能体学习
人工智能·学习·算法
黎阳之光5 小时前
黎阳之光:视频孪生领跑者,铸就中国数字科技全球竞争力
大数据·人工智能·算法·安全·数字孪生
skywalker_115 小时前
力扣hot100-3(最长连续序列),4(移动零)
数据结构·算法·leetcode
6Hzlia5 小时前
【Hot 100 刷题计划】 LeetCode 17. 电话号码的字母组合 | C++ 回溯算法经典模板
c++·算法·leetcode
_李小白6 小时前
【OSG学习笔记】Day 38: TextureVisitor(纹理访问器)
android·笔记·学习
wfbcg6 小时前
每日算法练习:LeetCode 209. 长度最小的子数组 ✅
算法·leetcode·职场和发展