-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphantichso.cpp
More file actions
60 lines (57 loc) · 1.11 KB
/
phantichso.cpp
File metadata and controls
60 lines (57 loc) · 1.11 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// created by:DungTD
//
#include <bits/stdc++.h>
#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define base int (1e9+7)
#define ll long long
using namespace std;
bool cauhinhcuoi = false;
vector <int> a;
void print() {
cout << "(";
for (int i=0; i<a.size()-1; i++) cout << a[i] << " ";
cout << a[a.size()-1] << ") ";
}
void sinh (int n) {
int i = a.size() - 1;
int sum = n;
while (i > -1 && a[i] == 1) {
sum -= a[i];
i--; a.pop_back();
}
// cout << "-" << i << "-";
if (i == -1) cauhinhcuoi = true;
else {
a[i] = a[i]-1;
sum -=1;
int tg = a[i];
while (sum < n) {
while (sum+tg <= n) {
sum += tg;
a.push_back(tg);
}
tg--;
}
}
}
void solve(){
int n; cin >> n;
cauhinhcuoi = false;
a.clear();
a.push_back(n);
while (!cauhinhcuoi) {
print();
sinh(n);
}
cout << endl;
}
int main(){
faster();
int t;
cin >> t;
while (t--)
solve();
return 0;
}