https://www.acwing.com/solution/acwing/content/2670/
Code
class Solution {
public :
Vector <Vector < int >> findContinuousSequence ( int SUM) {
Vector <Vector < int >> RES;
for ( int I = . 1 , J = . 1 , S = . 1 ; I <= SUM ; I ++ ) // consecutive positive number, starting from 1
{
// only when the sum s ==, out of the while
the while (S <sum) j ++, S + = j;
/ * if the current i and j is equal to the sum * /
IF (SUM && J == S - I +. 1> . 1) // consecutive positive sequence (containing at least two numbers), the interval length j-i + 1, should be greater than. 1
{
Vector < int > Line;
for ( int K = I ; K <= J ; K ++ ) line.push_back (K);
res.push_back (Line);
}
// after s == sum, and calculating the next set of consecutive positive sum of the number of sequences. i a rearward movement,
// i.e. case s = (i + 1) and to j.
S - = I;
}
return RES;
}
};