#P2232. [HNOI2002] 填数游戏

[HNOI2002] 填数游戏

Description

A store recently launched a promotional event with prizes for solving questions. The manager posted several challenging problems on the store’s bulletin board, and if you can solve any one of them, you can obtain the right to purchase goods at a discount. After some time, most problems were solved by customers, but there was one problem that stumped everyone. It is described as follows:

Fill every cell of an n×mn \times m rectangular grid with distinct perfect squares, such that the sum of each row and each column is also a perfect square (each such sum must be less than 1017{10}^{17}). Please find a valid arrangement.

Tiger hopes to earn the discount, so he turns to you, who are preparing for NOI 2002, and asks you to design a program to find a valid arrangement.

Input Format

The input consists of a single line with two positive integers n,mn, m (2n,m152 \le n, m \le 15).

Output Format

If a solution exists, output nn lines, each containing mm numbers that represent a valid arrangement. If there is no solution, output No answer.

2 2

225 1296
400 2304

Hint

Translated by ChatGPT 5