连续数字之和和输入的数字相等

来源:互联网 发布:js杀破狼歌曲下载 编辑:程序博客网 时间:2024/05/16 12:47
#include<iostream>
using namespace  std;
void main()
{int i;
 cin>>i;
int count=0;
int p=1;
 for(int begin=0;begin<=i/2+1;begin++)
 {
  count+=begin;
  while(count>i)
  {
   count-=p;
   p++;
  }
          if(count==i)
    {
     cout<<p<<"->"<<begin<<endl;
    }
 }
}
原创粉丝点击