CF1838C.No Prime Differences
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given integers n and m. Fill an n by m grid with the integers 1 through n⋅m, in such a way that for any two adjacent cells in the grid, the absolute difference of the values in those cells is not a prime number. Two cells in the grid are considered adjacent if they share a side.

It can be shown that under the given constraints, there is always a solution.
给定整数 n 和 m。请将 1 到 n⋅m 的整数填入一个 n 行 m 列的网格中,使得网格中任意两个相邻格子内的数值之差的绝对值都不是质数。若两个格子共享一条边,则称它们相邻。

在给定约束条件下,可以证明解总是存在。
输入格式
The first line of the input contains a single integer t (1≤t≤1000) — the number of test cases. The description of the test cases follows.
The first and only line of each test case contains two integers n and m (4≤n,m≤1000) — the dimensions of the grid.
It is guaranteed that the sum of n⋅m over all test cases does not exceed 106.
输入的第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例仅有一行,包含两个整数 n 和 m(4≤n,m≤1000),表示网格的尺寸。
保证所有测试用例中 n⋅m 的总和不超过 106。
输出格式
For each test case, output n lines of m integers each, representing the final grid. Every number from 1 to n⋅m should appear exactly once in the grid.
The extra spaces and blank lines in the sample output below are only present to make the output easier to read, and are not required.
If there are multiple solutions, print any of them.
对于每个测试用例,输出 n 行,每行 m 个整数,表示最终的网格。数字 1 到 n⋅m 在网格中必须恰好各出现一次。
下方样例输出中的额外空格和空行仅用于提升可读性,并非必需。
若存在多个解,输出任意一个即可。
输入输出样例
输入#1
3 4 4 5 7 6 4
输出#1
16 7 1 9 12 8 2 3 13 4 10 11 14 5 6 15 29 23 17 9 5 6 2 33 27 21 15 11 7 1 32 31 25 19 20 16 10 26 30 24 18 14 8 4 35 34 28 22 13 12 3 2 3 7 11 8 9 1 10 17 13 5 4 18 14 6 12 19 23 15 21 20 24 16 22
说明/提示
The first sample case corresponds to the picture above. The only absolute differences between adjacent elements in this grid are 1, 4, 6, 8, and 9, none of which are prime.
第一个样例对应于上方的图片。该网格中相邻元素之间唯一的绝对差值为 1、4、6、8 和 9,其中没有一个是质数。
输入解题思路,AI测评打分。不知道怎么写?