Magic Square

AtCoder
IDabc436_b
Time2000ms
Memory256MB
Difficulty
You are given an odd number $N$ that is at least $3$. There is a grid with $N$ rows and $N$ columns, where all cells are initially empty. Now, you will write integers in each cell of this grid according to the following procedure. Let $(i,j)$ denote the cell at the $(i+1)$\-th row from the top and $(j+1)$\-th column from the left ($0\leq i<N, 0\leq j<N$). 1. Write $1$ in cell $(0,\frac{N-1}{2})$. 2. Repeat the following operation $N^2-1$ times: * Let $(r,c)$ be the cell where an integer was written last time, and $k$ be the integer written. If cell $((r-1) \bmod N, (c+1) \bmod N)$ is empty, write $k+1$ in that cell; otherwise, write $k+1$ in cell $((r+1) \bmod N,c)$. Here, $x \bmod N$ denotes the remainder when $x$ is divided by $N$. Find the integer that will be written in each cell in this procedure. It can be proved that each cell will have an integer written in it exactly once. ## Constraints * $3\leq N \leq 99$ * $N$ is an odd number. ## Input The input is given from Standard Input in the following format: $N$ [samples]
Samples
Input #1
3
Output #1
8 1 6
3 5 7
4 9 2

Integers are written in each cell as follows:

1.  Write $1$ in cell $(0,\frac{3-1}{2})=(0,1)$.
2.  Cell $((0-1) \bmod 3, (1+1) \bmod 3)=(2,2)$ is empty, so write $2$ there.
3.  Cell $((2-1) \bmod 3, (2+1) \bmod 3)=(1,0)$ is empty, so write $3$ there.
4.  Cell $((1-1) \bmod 3, (0+1) \bmod 3)=(0,1)$ is not empty, so write $4$ in cell $((1+1) \bmod 3,0)=(2,0)$.
5.  $\vdots$
Input #2
5
Output #2
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
API Response (JSON)
{
  "problem": {
    "name": "Magic Square",
    "description": {
      "content": "You are given an odd number $N$ that is at least $3$. There is a grid with $N$ rows and $N$ columns, where all cells are initially empty. Now, you will write integers in each cell of this grid accordi",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc436_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an odd number $N$ that is at least $3$.\nThere is a grid with $N$ rows and $N$ columns, where all cells are initially empty. Now, you will write integers in each cell of this grid accordi...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments