#include <iostream>
using namespace std;
void Print(int i, int j)
{
for(int m = i; m <= j; m++)
{
cout<<m<<" ";
}
cout<<endl;
}
void FindContinuousSequence(int sum)
{
if( sum < 3 ) return ;
int i = sum / 2;
int j = begin + 1;
int tmpsum = i + j;
while(i > 0)
{
if( tmpsum == sum)
{
Print(i, j);
j--;
i = j-1;
tmpsum = i + j;
}
else if(tmpsum < sum)
{
i--;
tmpsum += i;
}
else
{
tmpsum -= j;
j--;
}
}
}
int main()
{
FindContinuousSequence(15);
getchar();
return 0;
}
和为sum的连续正整数序列
最新推荐文章于 2020-12-08 07:05:50 发布