-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUNITGCD.cpp
46 lines (45 loc) · 1.21 KB
/
UNITGCD.cpp
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
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
// your code goes here
int t;
//Input number of test cases
cin >> t;
while(t--) {
//Input number of pages to be read
int n;
cin >> n;
//If n is less than or equal to 3 then from 1 to n we can assign the pages on the same day.
//If n is greater than 3 then from 1 to 3 assign it to first day and successive 2 pages can be
//assigned on the next days until n.
//Number of days required is floor(n / 2) or (n / 2) in C++.
if (n <= 3) {
cout << 1 << "\n";
cout << n << " ";
for (int i = 1;i <= n;i++) {
cout << i << " ";
}
cout << "\n";
} else {
int count = n / 2;
cout << count << "\n";
cout << 3 << " ";
for (int i = 1;i <= 3;i++) {
cout << i << " ";
}
cout << "\n";
int i = 4;
while(i <= n) {
if (i + 1 <= n) {
cout << 2 << " " << i << " " << (i + 1) << "\n";
i += 2;
} else {
cout << 1 << " " << i << "\n";
i += 1;
}
}
}
}
return 0;
}