process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function main() { var n = parseInt(readLine()); for (let a = 1; a < n; a++) { let line = []; for (let b = 1; b < n; b++) line.push(bfs(n, a, b)); console.log(line.join(' ')); } } function bfs(n, a, b) { let distances = {}; distances["0 0"] = 0; let q = [{ x: 0, y: 0 }]; while (q.length) { let position = q.shift(); const moves = knight(a, b, position.x, position.y); for (let i = 0; i < moves.length; i++) { const move = moves[i]; if (move.x < 0 || move.y < 0 || move.x >= n || move.y >= n) continue; if (distances[move.x + ' ' + move.y] !== undefined) continue; distances[move.x + ' ' + move.y] = distances[position.x + ' ' + position.y] + 1; q.push(move); if (move.x == n - 1 && move.y == n - 1) return distances[move.x + ' ' + move.y]; } } return -1; } function knight(a, b, x, y) { let moves = []; [-1, 1].forEach(d => { [-1, 1].forEach(e => { moves.push({ x: x + d * a, y: y + e * b }); moves.push({ x: x + d * b, y: y + e * a }); }); }); return moves; }