#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int n; int table[25][25]; int delta_x[8], delta_y[8]; void back(int x, int y, int current_moves) { int i, new_x, new_y; if (table[x][y] > current_moves) { table[x][y] = current_moves; for (i = 0; i < 8; i++) { new_x = x + delta_x[i]; new_y = y + delta_y[i]; if (new_x >= 0 && new_x < n && new_y >= 0 && new_y < n) { back(new_x, new_y, current_moves + 1); } } } } int main() { int a, b, i, j, min_moves; int result[25][25]; cin >> n; for (a = 1; a < n; a++) for (b = a; b < n; b++) { delta_x[0] = a; delta_x[1] = a; delta_x[2] = -a; delta_x[3] = -a; delta_x[4] = b; delta_x[5] = b; delta_x[6] = -b; delta_x[7] = -b; delta_y[0] = b; delta_y[1] = -b; delta_y[2] = b; delta_y[3] = -b; delta_y[4] = a; delta_y[5] = -a; delta_y[6] = a; delta_y[7] = -a; for (i = 0; i < n; i++) for (j = 0; j < n; j++) table[i][j] = INT_MAX; back(0, 0, 0); min_moves = table[n - 1][n - 1]; if (min_moves != INT_MAX) result[a][b] = result[b][a] = min_moves; else result[a][b] = result[b][a] = -1; } for (a = 1; a < n; a++) { for (b = 1; b < n; b++) { cout << result[a][b] << " "; } cout << endl; } return 0; }