任务描述
本关任务:计算因数分解的种数。
给出一个正整数a
,要求分解成若干个正整数的乘积,即a = a1 * a2 * a3 * ... * an
,并且1 < a1 <= a2 <= a3 <= ... <= an
。问这样的分解的种数有多少?
注意:a = a
也是一种分解。
编程要求
右侧编辑器中有一个函数Count
,它有一个参数a
代表要进行分解的整数。
请在此函数中计算并输出a
进行因数分解的种数,占一行。
输入数据由评测系统读取,并传递给Count
函数。具体见测试说明。
测试说明
平台会对你编写的代码进行测试:
测试输入:2
预期输出:1
测试输入:20
预期输出:4
#include <iostream>
using namespace std;
/********** Begin **********/
int count(int a,int start)
{
if(a <= 2)
return 1;
int c = 1;
for(int s = start;s * s <= a;s++)
{
if(a % s == 0)
c += count(a / s,s);
}
return c;
}
void Count(int a)
{
cout << count(a,2) << endl;
}
int main()
{
int a;
while(cin >> a)
{
Count(a);
}
}