#P10925. Happybob's Pancake (UBC001E)

Happybob's Pancake (UBC001E)

Problem Description

Happybob wants to make a pancake. He decides to make it in a tilted square pan of size nn rows and nn columns, so the pancake cannot be larger than the tilted square.

Because the ingredients are limited, Happybob's pancake must be formed by covering with mm rectangles.

Happybob wants to know the maximum possible area of the pancake he can make.


Formal statement:

Use mm rectangles to cover a tilted square of size nn. What is the maximum number of cells that can be covered?

See the Explanation/Hint for the definitions of the tilted square and covering.

Input Format

The first line contains an integer TT, the number of queries.

The next TT lines each contain two integers n,mn, m, representing one query.

Output Format

Output TT lines, each line containing the answer for one query.

3
5 1
6 2
8 2
9
20
32

Hint

Sample Explanation

The solutions for the three queries are:

3

4

5

(The solutions are not unique.)

Constraints

1T501\le T\le 50, 1n2×1091\le n\le 2\times 10^9, 1mn21\le m\le\lceil\dfrac{n}{2}\rceil.


Formal Definitions

Definition of the tilted square:

More formally, build a Cartesian coordinate system, and define the center of a tilted square of size nn to be the origin.

If nn is odd, then this tilted square can be described as the combined shape formed by all unit square cells (with side length 11) whose centers are points in $\big\{(x, y) \big | |x| + |y| \le \lfloor \frac{n}{2} \rfloor \text{ and } x, y \in \Z\big\}$.

If nn is even, then this tilted square can be described as the combined shape formed by all unit square cells (with side length 11) whose centers are points in $\big\{(x, y) \big | |x| + |y| \le \frac{n}{2} \text{ and } (x + \frac{1}{2}), (y + \frac{1}{2}) \in \Z\big\}$.

A tilted square with n=5n=5 (light blue points are cell centers):

1

A tilted square with n=6n=6 (light blue points are cell centers):

2

Definition of the covering method:

Define that a rectangle RR covers this tilted square if and only if RR is a rectangle formed by several cells.

The following is a rectangle that covers a tilted square:

3

The following are not rectangles that cover a tilted square:

4

5

6

Define that a cell is covered if and only if among the chosen mm rectangles that cover the tilted square, at least one completely contains this cell.

Translated by ChatGPT 5