Avoid Prime Sum

AtCoder
IDarc149_c
Time2000ms
Memory256MB
Difficulty
You are given a positive integer $N$. Fill each square of a grid with $N$ rows and $N$ columns by writing a positive integer not greater than $N^2$ so that all of the following conditions are satisfied. * Two positive integers written in horizontally or vertically adjacent squares never sum to a prime number. * Every positive integer not greater than $N^2$ is written in one of the squares. Under the Constraints of this problem, it can be proved that such a way to fill the grid always exists. ## Constraints * $3\leq N\leq 1000$ ## Input The input is given from Standard Input in the following format: $N$ [samples]
Samples
Input #1
4
Output #1
15 11 16 12
13 3 6 9
14 7 8 1
4 2 10 5

In this grid, every positive integer from $1$ through $16$ is written once. Additionally, among the sums of two positive integers written in horizontally or vertically adjacent squares are $15+11=26$, $11+16=27$, and $15+13=28$, none of which is a prime number.
API Response (JSON)
{
  "problem": {
    "name": "Avoid Prime Sum",
    "description": {
      "content": "You are given a positive integer $N$. Fill each square of a grid with $N$ rows and $N$ columns by writing a positive integer not greater than $N^2$ so that all of the following conditions are satisfie",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc149_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a positive integer $N$.\nFill each square of a grid with $N$ rows and $N$ columns by writing a positive integer not greater than $N^2$ so that all of the following conditions are satisfie...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments