-
Notifications
You must be signed in to change notification settings - Fork 2
/
UnitGCD.cpp
51 lines (49 loc) · 978 Bytes
/
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
47
48
49
50
51
//https://www.codechef.com/APRIL20B/problems/UNITGCD/
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long int ll;
int main()
{
IO;
int t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
if(n<4)
{
if(n==1){
cout<<"1"<<"\n";
cout<<"1 1"<<"\n";}
else if(n==2){
cout<<"1"<<"\n";
cout<<"2 1 2"<<"\n";}
else if(n==3){
cout<<"1"<<"\n";
cout<<"3 1 2 3"<<"\n";}
}
else{
if(n%2==0){
cout<<(n/2L)<<"\n";
for(ll i=1;i<n;i+=2)
{
cout<<"2 "<<i<<" "<<(i+1L)<<"\n";
}
}
else{
cout<<(n/2L)<<"\n";
for(ll i=1;i<n;i+=2)
{
if(i<n-2)
cout<<"2 "<<i<<" "<<(i+1L)<<"\n";
else{
cout<<"3 "<<i<<" "<<(i+1L)<<" "<<(i+2L)<<"\n";
break;}
}
}
}
}
return 0;
}