atcoder#ARC149C. [ARC149C] Avoid Prime Sum
[ARC149C] Avoid Prime Sum
Score : points
Problem Statement
You are given a positive integer .
Fill each square of a grid with rows and columns by writing a positive integer not greater than 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 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
Input
The input is given from Standard Input in the following format:
Output
Print a way to fill the grid under the conditions in the following format, where is the positive integer at the -th row and -th column:
If there are multiple ways to fill the grid under the conditions, any of them will be accepted.
4
15 11 16 12
13 3 6 9
14 7 8 1
4 2 10 5
In this grid, every positive integer from through is written once. Additionally, among the sums of two positive integers written in horizontally or vertically adjacent squares are , , and , none of which is a prime number.