joj 2344: Dissolution of Integer 将N分解成乘积形式 共有多少种解法

本文介绍了一种用于计算正整数不同分解形式数量的高效算法,并提供了完整的C++实现代码。该算法通过预处理得到每个数的分解方式数量,进而快速响应查询请求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

As you known,a positive integer can be written to a form of products of several positive integers(N = x1 * x2 * x3 *.....* xm (xi!=1 (1<=i<=m))).Now, given a positive integer, please tell me how many forms of products.

Input

Input consists of several test cases.Given a positive integer N (2<=N<=200000) in every case.

Output

For each case, you should output how many forms of the products.

Sample Input

12
100
5968

Sample Output

4
9
12

 

 //

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=200001;
int a[maxn],prime[maxn],pl;
int main()
{
    a[1]=1;
    for(int i=2;i<maxn;i++)
    {
        for(int j=1;i*j<maxn;j++)
        {
            a[i*j]+=a[j];
        }
    }
    int n;
    while(scanf("%d",&n)==1)
    {
        printf("%d\n",a[n]);
    }
    return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值