#include #include #include #include #include #include #include #include using namespace std; int n; int path[26][26]; int used[26][26]; void gonull(){ for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) path[i][j] = used[i][j] = 0; } int find_path(int d1, int d2){ int a = d1, b = d2; queue > q; q.push(pair (0, 0)); used[0][0] = 1; while(!q.empty()){ pair v = q.front(); q.pop(); int x = v.first+a; int y = v.second+b; if (x >= 0 && x < n && y >= 0 && y < n){ if (used[x][y] == 0){ q.push(pair (x, y)); used[x][y] = 1; path[x][y] = path[v.first][v.second] + 1; } } x = v.first-a; y = v.second-b; if (x >= 0 && x < n && y >= 0 && y < n){ if (used[x][y] == 0){ q.push(pair (x, y)); used[x][y] = 1; path[x][y] = path[v.first][v.second] + 1; } } x = v.first-b; y = v.second-a; if (x >= 0 && x < n && y >= 0 && y < n){ if (used[x][y] == 0){ q.push(pair (x, y)); used[x][y] = 1; path[x][y] = path[v.first][v.second] + 1; } } x = v.first+b; y = v.second+a; if (x >= 0 && x < n && y >= 0 && y < n) if (used[x][y] == 0){ q.push(pair (x, y)); used[x][y] = 1; path[x][y] = path[v.first][v.second] + 1; } x = v.first-a; y = v.second+b; if (x >= 0 && x < n && y >= 0 && y < n){ if (used[x][y] == 0){ q.push(pair (x, y)); used[x][y] = 1; path[x][y] = path[v.first][v.second] + 1; } } x = v.first+a; y = v.second-b; if (x >= 0 && x < n && y >= 0 && y < n){ if (used[x][y] == 0){ q.push(pair (x, y)); used[x][y] = 1; path[x][y] = path[v.first][v.second] + 1; } } x = v.first+b; y = v.second-a; if (x >= 0 && x < n && y >= 0 && y < n){ if (used[x][y] == 0){ q.push(pair (x, y)); used[x][y] = 1; path[x][y] = path[v.first][v.second] + 1; } } x = v.first-b; y = v.second+a; if (x >= 0 && x < n && y >= 0 && y < n){ if (used[x][y] == 0){ q.push(pair (x, y)); used[x][y] = 1; path[x][y] = path[v.first][v.second] + 1; } } } return path[n-1][n-1]; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ cin >> n; for (int i = 1; i < n; ++i){ for (int j = 1; j < n; ++j){ int x = find_path(i, j); if (x == 0) cout << -1 << " "; else cout << x << " "; gonull(); } cout << '\n'; } }