-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path41.cpp
More file actions
41 lines (38 loc) · 1013 Bytes
/
41.cpp
File metadata and controls
41 lines (38 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int> > FindContinuousSequence(int sum) {
vector<vector<int> > res;
int low = 1, high = 2;
while (low < high) {
int tempsum = ((low + high) * (high - low + 1) >> 1);
if (tempsum == sum) {
vector<int> temp;
for (int i = low; i <= high; i++)
temp.push_back(i);
res.push_back(temp);
low++;
} else if (tempsum < sum)
high++;
else
low++;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
int sum;
vector<vector<int> > res;
vector<int> temp;
cin >> sum;
res = FindContinuousSequence(sum);
vector<vector<int> >::iterator iter;
vector<int>::iterator it;
for (iter = res.begin(); iter != res.end(); iter++) {
temp = *iter;
for (it = temp.begin(); it != temp.end(); it++)
cout << *it << " ";
cout << endl;
}
return 0;
}