#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; bool passed[26][26]; #define mp make_pair typedef pair pi; typedef pair pii; int n; bool inrange(int x, int y) { return x > 0 && x <= n && y > 0 && y <= n; } int bfs(int a, int b) { int dx[8] = {-a, -a, a, a, b, b, -b, -b}, dy[8] = {b, -b, -b, b, a, -a, -a, a}; memset(passed, 0, sizeof(passed)); queue qu; pii start = mp(mp(1, 1), 0); qu.push(start); while (qu.size()) { pii cur = qu.front(); qu.pop(); int steps = cur.second; int x = cur.first.first, y = cur.first.second; if (x == n && y == n) return steps; for (int i = 0; i < 8; i++) { int xx = x + dx[i], yy = y + dy[i]; if (!inrange(xx, yy) || passed[xx][yy]) continue; passed[xx][yy] = true; qu.push(mp(mp(xx, yy), steps + 1)); } } return -1; } int main(){ cin >> n; // your code goes here for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) cout << bfs(i, j) << " "; cout << "\n"; } return 0; }