#include #include #include #include #include #include #include int main() { int i, j, l, x, y, n, a, b, c; int polje[30][30] = { 0 }, rez[30][30] = { 0 }; scanf("%d", &n); for (i = 1; i < n; i++) { for (j = i; j < n; j++) { polje[i][j] = 1; polje[j][i] = 1; for (l = 1; ; l++) { c = 0; for (x = 0; x < n; x++) for (y = 0; y < n; y++) { if (polje[x][y] == 0) continue; if (polje[x][y] == l) { // down right if (((x + i) < n) && ((y + j) < n)) if (polje[x + i][y + j] == 0) { c = 1; polje[x + i][y + j] = l + 1; } // down left if (((x + i) < n) && ((y - j) >= 0)) if (polje[x + i][y - j] == 0) { c = 1; polje[x + i][y - j] = l + 1; } // up right if (((x - i) >= 0) && ((y + j) < n)) if (polje[x - i][y + j] == 0) { c = 1; polje[x - i][y + j] = l + 1; } // up left if (((x - i) >= 0) && ((y - j) >= 0)) if (polje[x - i][y - j] == 0) { c = 1; polje[x - i][y - j] = l + 1; } //***************************************************** // right down if (((x + j) < n) && ((y + i) < n)) if (polje[x + j][y + i] == 0) { c = 1; polje[x + j][y + i] = l + 1; } // right up if (((x + j) < n) && ((y - i) >= 0)) if (polje[x + j][y - i] == 0) { c = 1; polje[x + j][y - i] = l + 1; } // left down if (((x - j) >= 0) && ((y + i) < n)) if (polje[x - j][y + i] == 0) { c = 1; polje[x - j][y + i] = l + 1; } // left up if (((x - j) >= 0) && ((y - i) >= 0)) if (polje[x - j][y - i] == 0) { c = 1; polje[x - j][y - i] = l + 1; } } } if (polje[n - 1][n - 1] != 0) { rez[i][j] = polje[n - 1][n - 1]; rez[j][i] = polje[n - 1][n - 1]; for (a = 0; a < n; a++) for (b = 0; b < n; b++) polje[a][b] = 0; break; } if (c == 0) { rez[i][j] = -1; rez[j][i] = -1; for (a = 0; a < n; a++) for (b = 0; b < n; b++) polje[a][b] = 0; break; } } } } for (a = 1; a < n; a++) { for (b = 1; b < n; b++) { printf("%d ", rez[a][b]); } printf("\n"); } return 0; }