Acwing 870. 约数个数

这篇博客介绍了一个编程问题,即如何计算给定正整数乘积的约数个数。通过输入样例,程序展示了如何利用因数分解并计算每个质因数的指数来确定约数总数。该算法适用于处理不超过2×10^9的整数,并且对结果进行了模P运算以防止溢出。
摘要由CSDN通过智能技术生成

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

输入格式
第一行包含整数 n。

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

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

数据范围
1≤n≤100,
1≤ai≤2×109
输入样例:
3
2
6
8
输出样例:
12
在这里插入图片描述

#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <unordered_map>
using namespace std;

typedef unsigned long long ull;
const int N = 1000010,P=1e9+7 ;
int n, m,len=1;
int primes[N], cnt;
int a[N];

int main()
{
    int i,j,v=1;
    cin>>n;
    unordered_map<int,int>ma;
    for(i=0; i<n; i++)
    {
        int x;
        cin>>x;
        for(j=2; j<=x/j; j++)
        {
            while(x%j==0)
            {
               ma[j]++;
               x=x/j;
            }
        }
        if(x>1)ma[x]++;
    }
    long long cnt=1;//别忘开long long
    for(auto it=ma.begin();it!=ma.end();it++)
    cnt=cnt*((*it).second+1)%P;
    cout<<cnt;
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值