Skip to content

Commit fa94ead

Browse files
authored
Codechef: Positive AND
1 parent d371126 commit fa94ead

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
def main():
2+
t = int(input())
3+
res = [2,3,1]
4+
last = 3
5+
check = 4
6+
for _ in range(t):
7+
n = int(input())
8+
if n == 1:
9+
print(1)
10+
elif (n & (n-1)) == 0:
11+
print(-1)
12+
elif n <= last:
13+
for i in range(n):
14+
print(res[i], end=" ")
15+
print()
16+
else:
17+
for i in range(last):
18+
print(res[i], end=" ")
19+
last += 1
20+
while last <= n:
21+
if last == check:
22+
res.append(last + 1)
23+
res.append(last)
24+
print((last + 1), end=" ")
25+
print(last, end=" ")
26+
last += 2
27+
check *= 2
28+
else:
29+
print(last, end=" ")
30+
res.append(last)
31+
last += 1
32+
print()
33+
last -= 1
34+
return 0
35+
36+
main()

0 commit comments

Comments
 (0)