题目链接
http://bailian.openjudge.cn/practice/2749/
#include <iostream>
#include <cstdio>
using namespace std;
int f(int begin, int tot)
{
int res = 1; // 自己本身就是1个
if(begin == tot)
return 1;
if(begin > tot)
return 0;
for(int i=begin;i<tot;i++)
{
if(tot%i == 0)
{
res += f(i, tot/i);
}
}
return res;
}
int main()
{
int n, a;
scanf("%d", &n);
while(n--)
{
scanf("%d", &a);
printf("%d\n", f(2, a));
}
return 0;
}

本文介绍了一个使用递归算法解决特定数学问题的C++程序实例。该程序定义了一个名为f的函数,通过递归调用自身来计算从某个起始整数到目标整数之间的因数分解组合数量。
595

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



