fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define all(a) a.begin(),a.end()
  4. #define allr(a) a.rbegin(),a.rend()
  5. #define ll long long
  6. const ll mod = 1000000007;
  7.  
  8. int lset(int n){
  9. int cnt = 0;
  10. for(int i = 0; i < 32; i++){
  11. if(n&(1<<i)) cnt = i;
  12. }
  13. return cnt+1;
  14. }
  15.  
  16. int fun(vector<int>&v){
  17. int k = 0;
  18. for(int i = 0; i < v.size(); i++){
  19. if((i+1) & 1) k = k&v[i];
  20. else k = k|v[i];
  21. }
  22. return k;
  23. }
  24. void solve()
  25. {
  26. int n;cin>>n;
  27. vector<int> v;
  28.  
  29. if(n%2 == 0){
  30. cout << (1<<lset(n))-1 << endl;
  31. int ele = (1<<(lset(n)-1))-1;
  32. int a = 1,b = 3;
  33. n--;
  34. for(int i = 1; i < n-1; i++){
  35. if(i != a && i != b) v.push_back(i);
  36. }
  37. v.push_back(a),v.push_back(b),v.push_back(n-1),v.push_back(n);
  38. v.push_back(ele);
  39. } else {
  40. cout << n << endl;
  41. int a = 1,b = 3;
  42. for(int i = 1; i < n-1; i++){
  43. if(i != a && i != b) v.push_back(i);
  44. }
  45. v.push_back(a),v.push_back(b),v.push_back(n-1),v.push_back(n);
  46. }
  47.  
  48. cout << fun(v) << endl;
  49. for(auto it:v) cout << it << " ";
  50. cout << endl;
  51. }
  52.  
  53. int main()
  54. {
  55. ios::sync_with_stdio(false);
  56. cin.tie(0);
  57.  
  58. int t = 1;
  59. cin>>t;
  60. while(t--){
  61. solve();
  62. }
  63. return 0;
  64. }
Success #stdin #stdout 0.01s 5284KB
stdin
1
8
stdout
15
7
2 4 5 1 3 6 7 7