-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathPOSAND.CPP
53 lines (51 loc) · 1.04 KB
/
POSAND.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
52
53
#include <bits/stdc++.h>
using namespace std;
#define ll int
bool isPowerOfTwo(ll n)
{
return n!=0 && ((n&(n-1))==0);
}
int main()
{
ll t;
cin >> t;
while (t--)
{
ll n;
cin >> n;
set<ll> s;
if (n == 1)
{
cout << 1 << endl;
continue;
}
else if (isPowerOfTwo(n))
{
cout << -1 << endl;
}
else
{
cout<<2<<" "<<3<<" "<<1;
s.insert(2);
s.insert(3);
s.insert(1);
for (ll i = 4; i <= n; i++)
{
if (isPowerOfTwo(i))
{
cout << " " << i + 1 << " " << i;
s.insert(i + 1);
s.insert(i);
}
else
{
if (s.find(i) != s.end())
continue;
else
cout <<" "<< i;
}
}
cout << endl;
}
}
}