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;
}

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

被折叠的 条评论
为什么被折叠?



