Destroy Cells

All submissions for this problem are available.
### Read problem statements in [Hindi](http://www.codechef.com/download/translated/LTIME75/hindi/DESTCELL.pdf), [Bengali](http://www.codechef.com/download/translated/LTIME75/bengali/DESTCELL.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/LTIME75/mandarin/DESTCELL.pdf), [Russian](http://www.codechef.com/download/translated/LTIME75/russian/DESTCELL.pdf), and [Vietnamese](http://www.codechef.com/download/translated/LTIME75/vietnamese/DESTCELL.pdf) as well. Anas is playing an amazing game on a grid with $N$ rows and $M$ columns. The rows are numbered $1$ through $N$ from top to bottom and the columns are numbered $1$ through $M$ from left to right. Anas wants to destroy this grid. To do that, he wants to send two heroes from the top left cell to the bottom right cell:  The first hero visits cells in rowmajor order: $(1,1) \rightarrow (1,2) \rightarrow \ldots \rightarrow (1,M) \rightarrow (2,1) \rightarrow (2,2) \rightarrow \ldots \rightarrow (2,M) \rightarrow \ldots \rightarrow (N,M)$.  The second hero visits cells in columnmajor order: $(1,1) \rightarrow (2,1) \rightarrow \ldots \rightarrow (N,1) \rightarrow (1,2) \rightarrow (2,2) \rightarrow \ldots \rightarrow (N,2) \rightarrow \ldots \rightarrow (N,M)$. We know that each hero destroys the first cell he visits, rests in the next $K$ cells he visits without destroying them, then destroys the next cell he visits, rests in the next $K$ cells, destroys the next cell, and so on until he reaches (and rests in or destroys) the last cell he visits. Anas does not know the value of $K$. Therefore, for each value of $K$ between $0$ and $N \cdot M  1$ inclusive, he wants to calculate the number of cells that will be destroyed by at least one hero. Can you help him? ### Input  The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.  The first and only line of each test case contains two spaceseparated integers $N$ and $M$. ### Output For each test case, print a single line containing $N \cdot M$ spaceseparated integers as described above. ### Constraints  $1 \le T \le 100$  $2 \le N, M \le 1,000$  the sum of $N \cdot M$ over all test cases does not exceed $2 \cdot 10^6$ ### Subtasks **Subtask #1 (30 points):**  $2 \le N, M \le 50$  the sum of $N \cdot M$ over all test cases does not exceed $5,000$ **Subtask #2 (70 points):** original constraints ### Example Input ``` 1 2 3 ``` ### Example Output ``` 6 4 3 3 2 1 ``` ### Explanation **Example case 1:**  $K = 0$: All cells will be destroyed by the heroes.  $K = 1$: The first hero will destroy the cells $[(1,1), (1,3), (2,2)]$, while the second one will destroy the cells $[(1,1), (1,2), (1,3)]$.  $K = 2$: The first hero will destroy the cells $[(1,1), (2,1)]$, while the second one will destroy the cells $[(1,1), (2,2)]$.  $K = 3$: The first hero will destroy the cells $[(1,1), (2,2)]$, while the second one will destroy the cells $[(1,1), (1,3)]$.  $K = 4$: The first hero will destroy the cells $[(1,1), (2,3)]$ and the second one will also destroy the cells $[(1,1), (2,3)]$.  $K = 5$ : The first hero will destroy the cell $(1,1)$ and the second one will also destroy the cell $(1,1)$.Author:  i_love_islam 
Editorial  https://discuss.codechef.com/problems/DESTCELL 
Tags  i_love_islam 
Date Added:  28082019 
Time Limit:  2.5 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 