#P1549. [NOIP 1997 提高组] 棋盘问题
[NOIP 1997 提高组] 棋盘问题
Description
On an () board, fill in the numbers , so that the sum of any two adjacent numbers is a prime number.
For example, when , there is:
The adjacent pairs whose sums are prime are:
When , one possible arrangement is:
Here we stipulate that the top-left cell must contain the number .
Input Format
A single integer .
Output Format
If multiple solutions exist, output the arrangement whose sum of the first row and the first column is minimal. Output the board in lines, each containing integers separated by single spaces. If no solution exists, output NO.
1
NO
2
1 2
4 3
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号