#include #define rep(i, ss, ee) for (int i = ss; i < ee; ++i) using namespace std; // 進行方向 // 0 1 2 3 = d%4 // 右下左上 int dy[] = {0, 1, 0, -1}; int dx[] = {1, 0, -1, 0}; using vi = vector; using vvi = vector; vvi dp; int N; void input() { cin >> N; } void output() { rep(i, 0, N) { rep(j, 0, N) { printf("%03d", dp[i][j]); j == N - 1 ? printf("\n") : printf(" "); } } } void solve() { dp.resize(N, vi(N, 0)); int d = 0; int p = 2; int y = 0; int x = 0; dp[y][x] = 1; while (p <= N * N) { while (true) { int ny = y + dy[d]; int nx = x + dx[d]; if (0 <= ny && ny < N && 0 <= nx && nx < N && dp[ny][nx] == 0) { dp[ny][nx] = p; p++; y = ny; x = nx; } else { break; } } //進行方向 d++; d %= 4; } } int main() { input(); solve(); output(); }