#!/usr/bin/env python import sys pos_to_moves_map = {} # Return list of next positions for KnightL(a,b) for nxn board # and starting position of pos => (x,y). def get_next_positions(n, a, b, pos): next_pos = [] x, y = pos for x_move, y_move in [(a, b), (b, a)]: if (0 <= (x + x_move) <= n - 1) and (0 <= (y + y_move) <= n - 1): next_pos.append((x + x_move, y + y_move)) if (0 <= (x + x_move) <= n - 1) and (0 <= (y - y_move) <= n - 1): next_pos.append((x + x_move, y - y_move)) if (0 <= (x - x_move) <= n - 1) and (0 <= (y + y_move) <= n - 1): next_pos.append((x - x_move, y + y_move)) if (0 <= (x - x_move) <= n - 1) and (0 <= (y - y_move) <= n - 1): next_pos.append((x - x_move, y - y_move)) return list(set(next_pos)) # Return the minimum number of moves required to # go from (0,0) to (n-1,n-1) with KnightL(a,b) moves. def get_num_moves(n, a, b): pos_list = [] pos = (0, 0) pos_to_moves_map[pos] = 0 pos_list.append((pos, 0)) while pos_list: pos, moves = pos_list.pop(0) next_pos = get_next_positions(n, a, b, pos) next_pos_unvisited = [ p for p in next_pos if p not in pos_to_moves_map ] for p in next_pos_unvisited: if p == (n-1, n-1): return moves + 1 pos_to_moves_map[p] = moves + 1 pos_list.append((p, moves+1)) return -1 n = int(raw_input().strip()) for a in range(1, n): moves_list = [] for b in range(1, n): pos_to_moves_map.clear() # Find the min moves for a,b moves = get_num_moves(n, a, b) moves_list.append(str(moves)) print ' '.join(moves_list)