#include #define qmax 30*30 using namespace std; typedef struct cell{ int x, y; }CELL; int n; int BFS(int i, int j){ int first = 1, last = 0; int free[30][30] = {}, d[30][30] = {}; CELL q[qmax]; free[0][0] = 1; q[++last].x = 0; q[last].y= 0; while (first <= last){ CELL u = q[first++], v; if (u.x == n-1 && u.y == n-1) break; v.x = u.x + i; v.y = u.y + j; if (v.x >= 0 && v.x < n && v.y >= 0 && v.y < n) if (free[v.x][v.y] == 0){ d[v.x][v.y] = d[u.x][u.y] + 1; free[v.x][v.y] = 1; q[++last] = v; } v.x = u.x - i; v.y = u.y + j; if (v.x >= 0 && v.x < n && v.y >= 0 && v.y < n) if (free[v.x][v.y] == 0){ d[v.x][v.y] = d[u.x][u.y] + 1; free[v.x][v.y] = 1; q[++last] = v; } v.x = u.x + i; v.y = u.y - j; if (v.x >= 0 && v.x < n && v.y >= 0 && v.y < n) if (free[v.x][v.y] == 0){ d[v.x][v.y] = d[u.x][u.y] + 1; free[v.x][v.y] = 1; q[++last] = v; } v.x = u.x - i; v.y = u.y - j; if (v.x >= 0 && v.x < n && v.y >= 0 && v.y < n) if (free[v.x][v.y] == 0){ d[v.x][v.y] = d[u.x][u.y] + 1; free[v.x][v.y] = 1; q[++last] = v; } v.x = u.x + j; v.y = u.y + i; if (v.x >= 0 && v.x < n && v.y >= 0 && v.y < n) if (free[v.x][v.y] == 0){ d[v.x][v.y] = d[u.x][u.y] + 1; free[v.x][v.y] = 1; q[++last] = v; } v.x = u.x - j; v.y = u.y + i; if (v.x >= 0 && v.x < n && v.y >= 0 && v.y < n) if (free[v.x][v.y] == 0){ d[v.x][v.y] = d[u.x][u.y] + 1; free[v.x][v.y] = 1; q[++last] = v; } v.x = u.x + j; v.y = u.y - i; if (v.x >= 0 && v.x < n && v.y >= 0 && v.y < n) if (free[v.x][v.y] == 0){ d[v.x][v.y] = d[u.x][u.y] + 1; free[v.x][v.y] = 1; q[++last] = v; } v.x = u.x - j; v.y = u.y - i; if (v.x >= 0 && v.x < n && v.y >= 0 && v.y < n) if (free[v.x][v.y] == 0){ d[v.x][v.y] = d[u.x][u.y] + 1; free[v.x][v.y] = 1; q[++last] = v; } } if (d[n-1][n-1] == 0) return -1; else return d[n-1][n-1]; } int main(){ int a[30][30]; cin >> n; for(int i = 1; i< n; i++){ for(int j = 1; j< n; j++){ if (j >= i) a[i][j] = BFS(i, j); else a[i][j] = a[j][i]; } } for(int i = 1; i< n; i++){ for(int j = 1; j< n; j++) cout << a[i][j]<< " "; cout << endl; } return 0; }