import java.util.HashSet; import java.util.Objects; import java.util.Scanner; public class Solution { public static int res[][]; static int n; public static void main(String arg[]) { Scanner in = new Scanner(System.in); n = in.nextInt(); res = new int[n][n]; for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { System.out.print(calc(i, j) + " "); } System.out.println(); } } public static int calc(int i, int j) { int l = Math.min(i, j); int r = Math.max(j, i); if (res[l][r] != 0) return res[l][r]; int mcd = mcd(l, r); if (r == 1) return n - 1; else if (l == n - 1) return 1; else if (n % mcd > 1) return -1; else if (n % 2 == 1 && l == 1 && r == n - 1) return (n - 1) * 2; else if (n % 2 == 0 && l == 1 && r == n - 1) return n - 1; return res[l][r] = simulate(l, r); } public static int simulate(int j, int i) { HashSet movements = new HashSet<>(); movements.add(new Movement(i, j)); movements.add(new Movement(i, -j)); movements.add(new Movement(-i, j)); movements.add(new Movement(-i, -j)); movements.add(new Movement(j, i)); movements.add(new Movement(j, -i)); movements.add(new Movement(-j, i)); movements.add(new Movement(-j, -i)); Movement mvm[] = movements.toArray(new Movement[0]); int board[][] = new int[n][n]; for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) { board[x][y] = Integer.MAX_VALUE; } } board[0][0] = 0; int step = 0; boolean ff = true; while (ff) { ff = false; for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) { if (board[x][y] == step) { for (Movement movement : mvm) { int tox = x + movement.x; int toy = y + movement.y; if (tox == n - 1 && toy == n - 1) { return step + 1; } if (tox >= 0 && toy >= 0 && tox < n && toy < n && board[tox][toy] == Integer.MAX_VALUE) { board[tox][toy] = step + 1; ff = true; } } } } } step++; } return -1; } static class Movement implements Comparable { final int x; final int y; public Movement(int x, int y) { this.x = x; this.y = y; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Movement movement = (Movement) o; return x == movement.x && y == movement.y; } @Override public int hashCode() { return Objects.hash(x, y); } @Override public int compareTo(Movement o) { int xc = Integer.compare(this.x, o.x); if (xc != 0) return xc; return Integer.compare(this.y, o.y); } @Override public String toString() { final StringBuffer sb = new StringBuffer("Movement{"); sb.append("x=").append(x); sb.append(", y=").append(y); sb.append('}'); return sb.toString(); } } static int mcd(int a, int b) { int t; while (b != 0) { t = b; b = a % b; a = t; } return a; } }