题目收集
题目列表题单
返回列表

Rainbow

CodeforcesP0054· 1000ms· 256 MB· ZJU Summer 2026 Contest 5原题链接
构造

创建于 2026/07/18 · 更新于 2026/07/18

题目描述

Given a positive integer nnn. Construct an n×nn \times nn×n matrix AAA with n2n^2n2 elements Ai,jA_{i,j}Ai,j​(i,j∈{1,2,…,n}i,j \in \{1,2,\dots,n\}i,j∈{1,2,…,n}), such that:

  • ∀x∈{1,2,…,n2}\forall x \in \{1,2,\dots,n^2\}∀x∈{1,2,…,n2}, there exists a unique pair of (i,j)(i,j)(i,j) such that Ai,j=xA_{i,j}=xAi,j​=x.
  • ∀i,j∈{1,2,…,n}\forall i,j \in \{1,2,\dots,n\}∀i,j∈{1,2,…,n}, Ai,j≠i×jA_{i,j} \neq i \times jAi,j​=i×j.

输入格式

The input consists of one line, containing a single integer nnn(1≤n≤5001 \le n \le 5001≤n≤500).

输出格式

If there is no solution, output one line containing a single number −1-1−1.

Otherwise, the output should consist of nnn lines, each contains nnn positive numbers. The jjj-th number of line iii is Ai,jA_{i,j}Ai,j​.

If there are multiple solutions, you may output any of them.

样例输入 #1

3

样例输出 #1

3 8 4
5 2 1
9 7 6