fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4.  
  5. int check(int p)
  6. {
  7. return p != 0 && ((p & (p - 1)) == 0);
  8. }
  9.  
  10. int main()
  11. {
  12. int t;
  13. cin >> t;
  14. while (t--)
  15. {
  16. int n;
  17. cin >> n;
  18. if (n == 1)
  19. {
  20. cout << 1 << endl;
  21. continue;
  22. }
  23. else if (n == 3)
  24. {
  25. cout << 1 << " " << 3 << " " << 2 << endl;
  26. continue;
  27. }
  28. else if (n == 5)
  29. {
  30. cout << 2 << " " << 3 << " " << 1 << " " << 5 << " " << 4 << endl;
  31. continue;
  32. }
  33. else if (check(n))
  34. {
  35. cout << -1 << endl;
  36. continue;
  37. }
  38. else
  39. {
  40. cout << 2 << " " << 3 << " " << 1 << " " << 5 << " " << 4 << endl;
  41. int i = 6;
  42. while (i <= n)
  43. {
  44. if (check(i))
  45. {
  46. cout << i + 1 << " " << i << " ";
  47. i += 2;
  48. }
  49. else
  50. {
  51. cout << i << " ";
  52. i++;
  53. }
  54. }
  55. cout << endl;
  56. }
  57. }
  58. return 0;
  59. }
Success #stdin #stdout 0s 4528KB
stdin
1
1
stdout
1