Today we see a question about an integer represented as n consecutive integers. Search for the following article found:
Also search the implementation of the program: http://blog.csdn.net/Solstice/archive/2006/09/13/1217700.aspx
Http://squall.cs.ntou.edu.tw/cprog/Assignments/99Fall/FindGivenSum.html
Http://blog.chinaunix.net/u2/76292/showart_1359876.html (This is not true)
I also simple implementation of the following: (g++ compilation, the main idea is to use the arithmetic progression summation formula n= (a+a+k) * (k+2)/2 enumerate K, find the appropriate a)
#include <iostream>
#include <math.h>
using namespace std;
int main(){
int n;
cout<<"input n:"<<endl;
cin>>n;
int maxk=(int)sqrt((double)n*2);
int flag = 0;
//cout<<"maxk="<<maxk<<endl;
//for(int i=1;i<maxk+1;i++){
for(int i=maxk+1;i>0;i--){
double a = n/(double)(i+1)-i/(double)2;
//cout<<"a="<<a<<endl;
if(a>0&&a-(int)a==0){
//cout<<i<<endl;
for(int j=0;j<i+1;j++){
cout<<a+j<<" ";
}
cout<<endl;
flag=1;
}
}
if(flag==0){
cout<<"NONE"<<endl;
}
return 0;
}