Advertisement
SorahISA

CodeForces_1208_C

Aug 25th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. void solve() {
  2.     int magic[4][4] = {{ 8,  9,  1, 13},
  3.                        { 3, 12,  7,  5},
  4.                        { 0,  2,  4, 11},
  5.                        { 6, 10, 15, 14}};
  6.    
  7.     int n, N;
  8.     cin >> n;
  9.     N = n / 4;
  10.    
  11.     int square[n + 1][n + 1];
  12.    
  13.     for (int i = 0; i < n; i += 4) {
  14.         for (int j = 0; j < n; j += 4) {
  15.             int I = i / 4;
  16.             int J = j / 4;
  17.             for (int k = 0; k < 4; ++k) {
  18.                 for (int l = 0; l < 4; ++l) {
  19.                     square[i + k][j + l] = 16 * (I * N + J) + magic[k][l];
  20.                 }
  21.             }
  22.         }
  23.     }
  24.    
  25.     for (int i = 0; i < n; ++i) {
  26.         for (int j = 0; j < n; ++j) {
  27.             cout << square[i][j] << ' ';
  28.         }
  29.         cout << '\n';
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement