CF1436B.Prime Square
入门
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Sasha likes investigating different math objects, for example, magic squares. But Sasha understands that magic squares have already been studied by hundreds of people, so he sees no sense of studying them further. Instead, he invented his own type of square — a prime square.
A square of size n×n is called prime if the following three conditions are held simultaneously:
- all numbers on the square are non-negative integers not exceeding 105;
- there are no prime numbers in the square;
- sums of integers in each row and each column are prime numbers.
Sasha has an integer n. He asks you to find any prime square of size n×n. Sasha is absolutely sure such squares exist, so just help him!
萨沙喜欢研究各种数学对象,例如幻方。但萨沙明白幻方早已被数百人研究过,因此他认为继续研究幻方已无意义。于是,他发明了一种全新的方阵——素数方阵(prime square)。
一个 n×n 的方阵被称为素数方阵,当且仅当下列三个条件同时满足:
- 方阵中所有数均为不超过 105 的非负整数;
- 方阵中不包含任何素数;
- 每一行与每一列中所有整数的和均为素数。
萨沙给出一个整数 n。请你构造出任意一个 n×n 的素数方阵。萨沙确信这样的方阵一定存在,所以请直接帮他构造出来!
输入格式
The first line contains a single integer t (1≤t≤10) — the number of test cases.
Each of the next t lines contains a single integer n (2≤n≤100) — the required size of a square.
第一行包含一个整数 t(1≤t≤10)—— 测试用例的数量。
接下来的 t 行,每行包含一个整数 n(2≤n≤100)—— 所需正方形的边长。
输出格式
For each test case print n lines, each containing n integers — the prime square you built. If there are multiple answers, print any.
对于每个测试用例,输出 n 行,每行包含 n 个整数——即你构造的素数方阵。若存在多个答案,输出任意一个即可。
输入输出样例
输入#1
2 4 2
输出#1
4 6 8 1 4 9 9 9 4 10 10 65 1 4 4 4 1 1 1 1
输入解题思路,AI测评打分。不知道怎么写?