MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

CodeChef_problems/POSAND/solution.cpp:14–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12// eg 18 ---> 2 3 1 5 4 6 7 9 8 10 11 12 13 14 15 17 16 18
13
14int main(){
15// taking no of test cases as inputs
16 int T =0 ;
17 cin >> T;
18 while(T--){
19 int long N = 0;
20 cin >> N;
21 bool value = false;
22 // Condition to check if a number is a power of two..
23 if(ceil(log2(N)) == floor(log2(N)) && N !=1)
24 {
25 cout << -1<< "\n";
26 continue;
27 }
28 // For n=1 it is always 1
29 else if(N == 1) {
30 cout << 1<< "\n";
31 continue;
32 }
33 // running a loop till the required number.
34 for(int long i =1; i <=N; i++)
35 {
36 if(i==3)
37 {
38 cout << 1 << " ";
39 }
40 else if(ceil(log2(i)) == floor(log2(i)))
41 {
42 // if a power of two is encountered increment the i to the next no .. as it will be first in the series
43 cout << i+1<< " ";
44 // assign a true value that a power of two was encountered
45 value = true;
46 continue;
47 }
48 // if value of i was encounterd i+1th diz. was printed before.. print that power of two now.
49 else if(value == true)
50 {
51 cout << i-1<<" ";
52 // again set value to false.
53 value = false;
54 }
55 else
56 {
57 cout << i << " ";
58 }
59 }
60 printf("\n");
61 }
62 return 0;
63}
64

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected