AtCoder Regular Contest 149
翻译中…
Problem Statement
翻译中…
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
翻译中…
Output
翻译中…
Print a way to fill the grid under the conditions in the following format, where $A_{ij}$ is the positive integer at the $i$-th row and $j$-th column:
翻译中…
A_{11} \ldots A_{1N}
\vdots
A_{N1} \ldots A_{NN}
翻译中…
If there are multiple ways to fill the grid under the conditions, any of them will be accepted.
翻译中…
样例
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.
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。