1312 连续自然数和 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 对于一个自然数M,求出所有的连续的自然数段,使得这些连续自然数段的全部数字和为M.eg:1998+1999+2000+2001+2002=10000,所以从1998到2002的一个自然数段为M=10000的一个解。 输入描述 Input Description 一个数M 输出描述 Output Description 每行两个数,为连续自然数段的一头一尾,所有输出行的第一个数按照升序排列 样例输入 Sample Input 10000 样例输出 Sample Output 18 142 297 328 388 412 1998 2002 数据范围及提示 Data Size & Hint 分类标签 Tags 点此展开 数论 数论拜拜,枚举大水题! AC代码: #include<iostream> using namespace std; int main(){ int m;cin>>m; for(int i=1;i<m;i++){ int p=0; for(int j=i;p<m;j++){ p+=j; if(p==m){ cout<<i<<" "<<j<<"\n"; break; } } } return 0; } 转载于:https://www.cnblogs.com/shenben/p/5639913.html