#include #include #include using namespace std; bool onboard(int n, int x, int y) { return x >= 0 && x < n && y >=0 && y < n; } int minmoves(int n, int a, int b) { vector> board(n, vector(n)); board[0][0] = true; int moves = 0; using coords = vector>; coords last { make_pair(0, 0) }; while(!last.empty()) { ++moves; coords next; for(const auto& p: last) { array da = {a, -a}; array db = {b, -b}; for(int dx: da) { for(int dy: db) { int x = p.first + dx; int y = p.second + dy; if( x == n - 1 && y == n - 1) return moves; if(onboard(n, x, y) && !board[x][y]) { board[x][y] = true; next.emplace_back(x, y); } } } for(int dx: db) { for(int dy: da) { int x = p.first + dx; int y = p.second + dy; if( x == n - 1 && y == n - 1) return moves; if(onboard(n, x, y) && !board[x][y]) { board[x][y] = true; next.emplace_back(x, y); } } } } last = move(next); } return -1; } int main(){ int n; cin >> n; vector> result(n - 1, vector(n - 1)); for(int a = 1; a < n; ++a) { for(int b = a; b < n; ++b) { result[a - 1][b - 1] = result[b - 1][ a - 1] = minmoves(n, a, b); } } for(const auto& raw: result) { for(int x: raw) cout << x << ' '; cout << endl; } return 0; }