using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static bool IterateFrom(int x, int y, int a, int b, int n, int[,] r) { bool change = false; if (x >= a) { if (y >= b && 0>r[x - a, y - b]) { r[x - a, y - b] = r[x,y]+1;; change = true; } if (y < n - b && 0 > r[x - a, y + b]) { r[x - a, y + b] = r[x, y] + 1; ; change = true; } } if (x < n - a) { if (y >= b && 0 > r[x + a, y - b]) { r[x + a, y - b] = r[x, y] + 1; ; change = true; } if (y < n - b && 0 > r[x + a, y + b]) { r[x + a, y + b] = r[x, y] + 1; ; change = true; } } if (x >= b) { if (y >= a && 0 > r[x - b, y - a]) { r[x - b, y - a] = r[x, y] + 1; ; change = true; } if (y < n - a && 0 > r[x - b, y + a]) { r[x - b, y + a] = r[x, y] + 1; ; change = true; } } if (x < n - b) { if (y >= a && 0 > r[x + b, y - a]) { r[x + b, y - a] = r[x,y]+1; change = true; } if (y < n - a && 0 > r[x + b, y + a]) { r[x + b, y + a] = r[x, y] + 1; ; change = true; } } return change; } static int KnightGoToCorner(int a, int b, int n) { int [,] dist = new int[n, n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dist[i, j] = -1; bool changes = true; dist[0, 0] = 0; int step = 0; while (changes && dist[n - 1, n - 1] < 0) { step++; changes = false; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (dist[i, j] == step - 1) { bool c = IterateFrom(i, j, a, b, n, dist); changes = c | changes; } } } return (dist[n - 1, n - 1]>=0 ? dist[n-1,n-1] : -1); } static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); int[,] m = new int[n - 1, n - 1]; for (int i = 1; i < n; i++) for (int j = i; j < n; j++) { m[i - 1, j - 1] = KnightGoToCorner(i, j, n); m[j - 1, i - 1] = m[i - 1, j - 1]; } for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - 1; j++) { Console.Write("{0} ", m[i, j]); }; Console.WriteLine(); } } }