#include #include #include #include #include #include #include using namespace std; int explore(int n, int a, int b){ std::vector > visited(n, vector(n, false)); std::vector > get(n, vector(n, -1)); queue > myQueue; myQueue.push(make_pair(0,0)); get[0][0] = 0; visited[0][0] = true; while(!myQueue.empty()){ pair current = myQueue.front(); int x = current.first, y = current.second; vector > temp; if(x + a < n && y + b < n) temp.push_back(make_pair(x + a, y + b)); if(x + a < n && y - b >= 0) temp.push_back(make_pair(x + a, y - b)); if(x - a >= 0 && y + b < n) temp.push_back(make_pair(x - a, y + b)); if(x - a >= 0 && y - b >= 0) temp.push_back(make_pair(x - a, y - b)); if(y + a < n && x + b < n) temp.push_back(make_pair(x + b, y + a)); if(y + a < n && x - b >= 0) temp.push_back(make_pair(x - b, y + a)); if(y - a >= 0 && x + b < n) temp.push_back(make_pair(x + b, y - a)); if(y - a >= 0 && x - b >= 0) temp.push_back(make_pair(x - b, y - a)); for(int i = 0; i < temp.size(); i++){ int u = temp[i].first; int v = temp[i].second; // cout << "processing at " << u << " " << v << endl; if(!visited[u][v]){ visited[u][v] = true; get[u][v] = get[x][y] + 1; myQueue.push(make_pair(u, v)); } } myQueue.pop(); } return get[n-1][n-1]; } void process(int n){ for(int i = 0; i < n-1; i++){ for(int j = 0; j < n-1; j++){ cout << explore(n, i+1, j+1) << " "; } cout << endl; } } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; cin >> n; process(n); return 0; }