jatarc2004

Untitled

Apr 13th, 2025
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. const int MOD=1e9+7;
  6. const int INF=1e18;
  7.  
  8. int bin_pow(int a, int b){
  9.     int ans=1;
  10.     while(b){
  11.         if(b&1){
  12.             ans*=a;
  13.         }
  14.         a*=a;
  15.         b>>=1;
  16.     }
  17.     return ans;
  18. }
  19.  
  20. signed main(){
  21.     ios_base::sync_with_stdio(false);
  22.     cin.tie(NULL);
  23.     int t;
  24.     cin>>t;
  25.     while(t--){
  26.         int n;
  27.         cin>>n;
  28.         if(n==2){
  29.             cout<<"1 2"<<'\n';
  30.         }
  31.         else if(n==4){
  32.             cout<<"4 1 3 2"<<'\n';
  33.         }
  34.         else{
  35.             if(n%4==1){
  36.                 for(int i=1; i<=n; i++) cout<<i<<" ";
  37.                 cout<<'\n';
  38.             }
  39.             else if(n%4==2){
  40.                 for(int i=1; i<=n; i++){
  41.                     if(i!=3 && i!=4) cout<<i<<" ";
  42.                     else if(i==3) cout<<4<<" ";
  43.                     else cout<<3<<' ';
  44.                 }
  45.                 cout<<'\n';
  46.             }
  47.             else if(n%4==3){
  48.                 for(int i=1; i<n-2; i++) cout<<i<<" ";
  49.                 cout<<n<<" "<<n-2<<" "<<n-1<<'\n';
  50.             }
  51.             else{
  52.                 for(int i=1; i<n-4; i++) cout<<i<<" ";
  53.                 cout<<n-1<<" "<<n-4<<" "<<n-3<<" "<<n<<" "<<n-2<<'\n';
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment