Created
March 23, 2023 14:16
-
-
Save qjatn0120/7590773b72dd4b4de86cc975eeb2ed89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef DEBUG | |
#include "debug.h" | |
#endif // DEBUG | |
#ifndef DEBUG | |
template <typename T> | |
void debug(T &x){} | |
template <typename T> | |
void debug(T &x, int i, int j){} | |
#endif // DEBUG | |
#include <bits/stdc++.h> | |
using namespace std; | |
int main(){ | |
cin.tie(nullptr), ios::sync_with_stdio(false); | |
int T; | |
cin >> T; | |
while(T--){ | |
int N; | |
cin >> N; | |
if(N == 4){ | |
cout << "12 10 6 14\n3 8 4 1\n5 15 11 9\n2 7 13 16\n"; | |
}else{ | |
vector <int> v; | |
for(int i = 1; i <= N; i+= 2) v.push_back(i); | |
for(int i = 2; i <= N; i+= 2) v.push_back(i); | |
for(int r = 0; r < N; r++){ | |
for(int i : v) cout << (i + r * N) << " "; | |
cout << "\n"; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment