CF1918A.Brick Wall

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

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 (k≥2k \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.

砖是一条尺寸为 1×k1 \times k 的条状物,可水平或垂直放置,其中 kk 是任意大于等于 22 的整数(即 k≥2k \ge 2)。

一个 n×mn \times m 规格的砖墙,是指将若干块砖放入一个 n×mn \times m 的矩形区域内的一种方式,要求:所有砖均严格水平或垂直地放置在单元格中、不超出矩形边界,且该 n×mn \times m 矩形中的每个单元格恰好属于一块砖。此处 nn 表示矩形 n×mn \times m 的高度,mm 表示其宽度。注意:同一面砖墙中可以包含不同 kk 值的砖。

墙的稳定性定义为:水平放置的砖的数量与垂直放置的砖的数量之差。注意:例如若使用了 00 块水平砖和 22 块垂直砖,则稳定性为 −2-2,而非 22。

对于一个 n×mn \times m 规格的砖墙,其可能达到的最大稳定性是多少?

题目保证:在本题给定的约束条件下,至少存在一种合法的 n×mn \times m 砖墙。

输入格式

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

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

输入的第一行包含一个整数 tt(1≤t≤10 0001 \le t \le 10\,000),表示测试用例的数量。

每个测试用例仅有一行,包含两个整数 nn 和 mm(2≤n, m≤1042 \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.

对于每个测试用例,输出一个整数,表示尺寸为 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.

在第 1 个测试用例中,通过将两块 1×21 \times 2 的水平砖块上下叠放,可获得最大稳定性值 22。

在第 2 个测试用例中,通过在全部 77 行中每行放置 44 块 1×21 \times 2 的水平砖块,可获得最大稳定性值 2828。

输入解题思路,AI测评打分。不知道怎么写?

首页