luogu#P1549. [NOIP 1997 提高组] 棋盘问题
[NOIP 1997 提高组] 棋盘问题
Background
NOIP 1997 Senior, Problem 1.
P5512 is the enhanced testdata version of this problem.
The actual constraints for this problem are . There is no guarantee that a solution without hardcoding can pass the original constraints.
Problem 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