Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define int long long
- const int MOD=1e9+7;
- const int INF=1e18;
- int bin_pow(int a, int b){
- int ans=1;
- while(b){
- if(b&1){
- ans*=a;
- }
- a*=a;
- b>>=1;
- }
- return ans;
- }
- signed main(){
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int t;
- cin>>t;
- while(t--){
- int n;
- cin>>n;
- if(n==2){
- cout<<"1 2"<<'\n';
- }
- else if(n==4){
- cout<<"4 1 3 2"<<'\n';
- }
- else{
- if(n%4==1){
- for(int i=1; i<=n; i++) cout<<i<<" ";
- cout<<'\n';
- }
- else if(n%4==2){
- for(int i=1; i<=n; i++){
- if(i!=3 && i!=4) cout<<i<<" ";
- else if(i==3) cout<<4<<" ";
- else cout<<3<<' ';
- }
- cout<<'\n';
- }
- else if(n%4==3){
- for(int i=1; i<n-2; i++) cout<<i<<" ";
- cout<<n<<" "<<n-2<<" "<<n-1<<'\n';
- }
- else{
- for(int i=1; i<n-4; i++) cout<<i<<" ";
- cout<<n-1<<" "<<n-4<<" "<<n-3<<" "<<n<<" "<<n-2<<'\n';
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment