题目描述
Background
This is an enhanced version of the data from P1549.
The data range has been expanded from 5 to 10.
Due to potential controversies in the data, a new problem has been opened to test the enhanced data.
Problem Description
On an $N \times N$ ($1 \le N \le 10$) chessboard, fill in the numbers $1, 2, \dots, N^2$ such that the sum of any two adjacent numbers is a prime number.
For example, when $N = 2$, one possible arrangement is:
| $1$ | $2$ |
|---|---|
| $4$ | $3$ |
The sums of adjacent numbers that are prime include:
$1+2, 1+4, 4+3, 2+3$
When $N = 4$, one possible arrangement is:
| $1$ | $2$ | $11$ | $12$ |
|---|---|---|---|
| $16$ | $15$ | $8$ | $5$ |
| $13$ | $4$ | $9$ | $14$ |
| $6$ | $7$ | $10$ | $3$ |
We stipulate that the top-left corner must be filled with the number $1$.
Input Format
A single integer $N$.
Output Format
If there are multiple solutions, output the arrangement where the sum of the first row and the first column is the smallest. If there is no solution, output NO.
Sample Input and Output
Sample Input #1
2
Sample Output #1
1 2
4 3
Sample Input #2
1
Sample Output #2
NO
Notes
$N \leq 10$
There is one test case for each $N = 1, 2, ..., 10$. Due to certain reasons, $N$ may not be equal to the test case number.
Data updated on 2020.1.20
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分