C++等差数列
和为S的连续正数序列
http://www.nowcoder.com/questionTerminal/c451a3fd84b64cb19485dad758a55ebe
class Solution { public: //S=n(a1+a2)/2 vector<vector<int> > FindContinuousSequence(int sum) { vector<vector<int>> ans; int &s = sum; int up = sum-1; int n = up; while(n>=2) { int a1 = ((((2*s - n*n + n)%(2*n))%(2*n))==0)?((((2*s - n*n + n)/(2*n)))):-1; if(a1!=-1&&a1>0) { vector<int> temp; for(int i=a1;i<a1+n;i++) temp.push_back(i); ans.push_back(temp); } --n; } return ans; } };