Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

GCD Grid

By alamkhan · Limits 1s, 512 MB

You are given two integers $N$ and $M$.

You have to make a grid of $N* M$ size by following these rules:

1. Each cell in the grid must have exactly one integer number.
2. All numbers in the grid should be pairwise distinct. That means each number can't be repeated more than once.
3. Let's say,GCD of all numbers in $i$th row is $Ri$ where $(1<=i<=N)$. All $Ri$ should be pairwise distinct and $Ri > 1$.
4. Let's say,GCD of all numbers in $j$th column is $Cj$ where $(1<=j<=M)$. All $Cj$ should be pairwise distinct and $Cj > 1$.
5. All numbers in the grid should be greater than $1$ and less than $10^9$.

It is guaranteed that under these constraints the answer always exists.

If there are multiple answers, you may print any of them.

Input

Input contains two integers $N$ and $M (1<=N,M<=1000).$

Output

Output should contain $N$ lines. For each line print $M$ space separated integers. See sample output for more details.

Sample

InputOutput
2 3
3 6 12
48 24 16

In Sample Output:

1. Exactly one integer number in each cell of the grid.
2. All numbers in the grid are pairwise distinct.
3. GCD of all numbers in 1st row is 3, 2nd row is 8 which are greater than 1 and pairwise distinct.
4. GCD of all numbers in 1st column is 3, 2nd column is 6, 3rd column is 4 which are greater than 1 and pairwise distinct.
5. All numbers are greater than 1 and less than $10^9$. NumberTheory

Statistics

68% Solution Ratio

Tanveer2202Earliest, 4M ago

likhon5Fastest, 0.0s

MatrixLightest, 8.7 MB

akash740Shortest, 561B

Submit 