forked from larissalages/code_problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ3_Positive_AND__long_oct.cpp
More file actions
65 lines (62 loc) · 1.3 KB
/
Q3_Positive_AND__long_oct.cpp
File metadata and controls
65 lines (62 loc) · 1.3 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
/*
contest link : https://www.codechef.com/OCT20B
question link : https://www.codechef.com/OCT20B/problems/POSAND
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
scanf("%lld",&t);
while(t--)
{
long long int n,flag=0;
scanf("%lld",&n);
long long int k=1;
while(pow(2,k)<n)
{
k++;
if(pow(2,k)==n)
flag=1;
}
if(n==2)
printf("-1");
else if(flag==1)
printf("-1\n");
else if(n==1)
printf("1\n");
else if(n==3)
{
printf("2 3 1\n");
}
else
{
printf("2 3 1");
long long int i=3;
long long int m=2;
while(m<=k&&i<n)
{
long long int a=pow(2,m)+1;
long long int b=pow(2,m);
printf(" %lld %lld",a,b);
i=i+2;
long long int j=2;
while(1)
{
if(i==n)
break;
long long int d=pow(2,m)+j;
printf(" %lld",d);
j++;
i++;
if(d==(pow(2,m+1)-1))
{
m++;
break;
}
}
}
}
printf("\n");
}
return 0;
}