CF1485D Multiples and Power Differences
You are given a matrix consisting of positive integers. It has rows and columns.
Construct matrix consisting of positive integers. It should have the same size as , and the following conditions should be met:
- ;
- is a multiple of ;
- the absolute value of the difference between numbers in any adjacent pair of cells (two cells that share the same side) in - is equal to for some integer ( is not necessarily the same for all pairs, it is own for each pair).
We can show that the answer always exists.
Input
The first line contains two integers and ().
Each of the following lines contains integers. The -th integer in the -th line is ().
Output
The output should contain lines each containing integers. The -th integer in the -th line should be .
Examples
input
1 | 2 2 |
output
1 | 1 2 |
input
1 | 2 3 |
output
1 | 16 32 48 |
input
1 | 2 2 |
output
1 | 327 583 |
Note
In the first example, the matrix can be used as the matrix , because the absolute value of the difference between numbers in any adjacent pair of cells is .
In the third example:
is a multiple of , is a multiple of , is a multiple of , is a multiple of ;
, , , .
Idea
,而 的最小公倍数只有 ,这就给了启发。
在 为偶数的位置填 ,否则填 ,即符合题意。
Code
1 | /****************************************************************** |