You are given a rectangle of height $$H$$ and width $$W$$. You must divide this rectangle exactly into three pieces such that each piece is a rectangle of integral height and width. You are required to minimize \(Area_{max}-Area_{min}\) where \(Area_{max}\) is the area of the largest rectangle and \(Area_{min}\) is the area of the smallest rectangle, among all three rectangle pieces.
Input format
- The first line contains an integer $$T$$ denoting the number of test cases.
- The first line of each test case contains two space-separated integers $$H$$ and $$W$$ denoting the height and width of the rectangle.
Output format
For each test case, print the minimum possible value of \(Area_{max}-Area_{min}\) in a new line.
Constraints
- It is guaranteed that the sum of $$H$$ over $$T$$ test cases does not exceed $$1e6$$.
- It is guaranteed that the sum of $$W$$ over $$T$$ test cases does not exceed $$1e6$$.
2 3 4 2 2
0 1
For both the test cases, the division is shown below:
For the first testcase $$Area_{max}-Area_{min}$$ = $$4-4=0$$.
For the first testcase $$Area_{max}-Area_{min}$$ = $$2-1=1$$.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor