-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPOSAND.cpp
More file actions
45 lines (42 loc) · 693 Bytes
/
POSAND.cpp
File metadata and controls
45 lines (42 loc) · 693 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
42
43
44
45
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
void solve(int n,int curr) {
while(curr <= n) {
if(log2(curr) - (int)log2(curr) == 0) {
if(curr+1 > n) {
break;
}
cout << curr + 1 << " ";
cout << curr << " ";
curr +=2;
} else {
cout << curr << " ";
curr += 1;
}
}
cout << endl;
}
int main()
{
// freopen("input.txt","r",stdin);
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
if(n == 1) {
cout << 1 << endl;
}
else if(log2(n) - (int)log2(n) == 0) {
cout << -1 << endl;
} else if(n == 3) {
cout << "1 3 2" << endl;
} else {
cout << "2 3 1 5 4 ";
solve(n,6);
}
}
return 0;
}