using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < n-1; i++) { for (int j = 0; j < n-1; j++) { int res = Calculate(i+1, j+1, n-1); Console.Write(res+" "); if (j==(n-2)) { Console.WriteLine(); } } } } private static int Calculate(int a, int b, int n) { if (a == b && a == n) return 1; if ((a == n - 1 && b == n) || (b == n - 1 && a == n)) { return -1; } int counter = 2; int sum = a + b; int sub = Math.Abs(a - b); int start = sum; int finish = 2 * n - sum; List path=new List(); List previousList=new List(); int prev = start; previousList.Add(prev); while (start != finish) { int next = prev + sum; if (next > 2*n || previousList.Contains(next)) { next = prev - sum; if (next < 0 || previousList.Contains(next)) { next = prev + sub; if (next > 2*n || previousList.Contains(next)) { next = prev - sum; if (next < 0 || previousList.Contains(next)) { return -1; } } } } start = next; prev = start; previousList.Add(prev); counter++; } if ((a == n && b==1) || (b == n && a==1)) { return counter*2; } return counter == n*2 ? counter/2 : counter; } }