#P2232. Distinct Perfect Square Grid
Distinct Perfect Square Grid
Distinct Perfect Square Grid
A store is running a promotional quiz event with a twist: the manager has posted several challenging puzzles on the notice board. If you can solve one of the puzzles, you’ll receive a discount on your purchase. After a while, almost every puzzle was solved by the customers – except one. This unsolved puzzle is described as follows:
Fill an \(n \times m\) grid with distinct perfect square numbers such that the sum of each row and each column is also a perfect square. Moreover, every row or column sum must be less than \(10^{17}\). In other words, if \(a_{ij}\) represents the number in the \(i\)th row and \(j\)th column, then:
[ \begin{aligned} &\text{For all } 1 \le i \le n, ; \sum_{j=1}^{m} a_{ij} = k_i^2,\[6pt] &\text{For all } 1 \le j \le m, ; \sum_{i=1}^{n} a_{ij} = l_j^2,\[6pt] &\text{and } a_{ij} = x^2 ; \text{with all } a_{ij} \text{ distinct}, \end{aligned} ]
Your task is to help Tiger (a hopeful participant in NOI2002) by writing a program that outputs any valid grid that meets the above conditions.
inputFormat
The input consists of two positive integers \(n\) and \(m\) representing the number of rows and columns of the grid.
For example:
1 2
outputFormat
Output an \(n\) x \(m\) grid. Each line should contain \(m\) space‐separated numbers. Every number must be a distinct perfect square and the sum of each row and each column must be a perfect square (and less than \(10^{17}\)). If multiple solutions exist, output any one of them.
sample
1 1
1