#include <cmath>
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
long c, k, m, n, t;
scanf("%ld", &n);
t = (long)sqrt(2 * n);
c = 0;
for (k = 2; k <= t; k++) {
if ((2 * n) % k > 0 || (2 * n / k + 1 - k) % 2 > 0)
continue;
m = (2 * n / k + 1 - k) / 2;
c++;
cout << "%d: %d+...%d\n" << c << m << m + k - 1 << endl;
}
cout << "sum is:" << c << endl;
return 0;
}
运用求和公式拆分连续正整数之和
最新推荐文章于 2024-07-13 20:45:35 发布
这是一个使用C++编写的程序,该程序通过输入一个数值n来找出所有可能的连续正整数序列,这些序列的和等于n。程序首先计算了一个阈值t,接着遍历从2到t的所有整数k,检查是否可以将2n整除k且满足其他条件,如果满足,则计算相应的m值并输出。
824

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



