CF1918A.Brick Wall

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A brick is a strip of size 1×k1 \times k , placed horizontally or vertically, where kk can be an arbitrary number that is at least 22 ( k2k \ge 2 ).

A brick wall of size n×mn \times m is such a way to place several bricks inside a rectangle n×mn \times m , that all bricks lie either horizontally or vertically in the cells, do not cross the border of the rectangle, and that each cell of the n×mn \times m rectangle belongs to exactly one brick. Here nn is the height of the rectangle n×mn \times m and mm is the width. Note that there can be bricks with different values of k in the same brick wall.

The wall stability is the difference between the number of horizontal bricks and the number of vertical bricks. Note that if you used 00 horizontal bricks and 22 vertical ones, then the stability will be 2-2 , not 22 .

What is the maximal possible stability of a wall of size n×mn \times m ?

It is guaranteed that under restrictions in the statement at least one n×mn \times m wall exists.

输入格式

The first line of the input contains one integer tt ( 1t100001 \le t \le 10\,000 ), the number of test cases.

The only line of each test case contains two integers nn and mm ( 2n,m1042 \le n,\,m \le 10^4 ).

输出格式

For each test case, print one integer, the maximum stability of a wall of size n×mn \times m .

输入输出样例

  • 输入#1

    5
    2 2
    7 8
    16 9
    3 5
    10000 10000

    输出#1

    2
    28
    64
    6
    50000000

说明/提示

In the 1st test case, the maximum stability of 22 is obtained by placing two horizontal bricks 1×21 \times 2 one on top of the other.

In the 2nd test case, one can get the maximum stability of 2828 by placing 44 horizontal bricks 1×21 \times 2 in each of the 77 rows.

首页