【题目】
【分析】
详细详见:点击打开链接
【代码】
/********************************* * 日期:2014-04-26 * 作者:SJF0115 * 题目: 高斯公式 * 来源:http://hero.csdn.net/Question/Details?ID=537&ExamID=532 * 结果:AC * 来源:庞果网 * 总结: **********************************/ #include <iostream> #include <stdio.h> using namespace std; int main(){ int n,i; while(scanf("%d",&n) != EOF){ int small = 1; int big = 2; int mid = (1 + n) / 2; int count = 0; int cur = small + big; while(small < mid){ //cur = n if(cur == n){ count ++; } //cur > n while(cur > n && small < mid){ cur -= small; small ++; if(cur == n){ count++; } }//while //cur < n big ++; cur += big; }//while printf("%d\n",count+1); } return 0; }
原文地址:http://www.cnblogs.com/hrhguanli/p/3776231.html