测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A15303. Accumulation of Dominoes

编程题 普及/提高-

题目描述

Pak Chanek has a grid that has $N$ rows and $M$ columns. Each row is numbered from $1$ to $N$ from top to bottom. Each column is numbered from $1$ to $M$ from left to right.

Each tile in the grid contains a number. The numbers are arranged as follows:

- Row $1$ contains integers from $1$ to $M$ from left to right.
- Row $2$ contains integers from $M+1$ to $2 \times M$ from left to right.
- Row $3$ contains integers from $2 \times M+1$ to $3 \times M$ from left to right.
- And so on until row $N$ .

A domino is defined as two different tiles in the grid that touch by their sides. A domino is said to be tight if and only if the two numbers in the domino have a difference of exactly $1$ . Count the number of distinct tight dominoes in the grid.

Two dominoes are said to be distinct if and only if there exists at least one tile that is in one domino, but not in the other.

输入格式

The only line contains two integers $N$ and $M$ ( $1 \leq N, M \leq 10^9$ ) — the number of rows and columns in the grid.

输出格式

An integer representing the number of distinct tight dominoes in the grid.

输入输出样例

输入 #1
3 4
输出 #1
9
输入 #2
2 1
输出 #2
1

说明/提示

The picture below is the grid that Pak Chanek has in the first example.

![](/uploads/acgo/image/92781562749a5c16_078202ef4e35.jpeg)The picture below is an example of a tight domino in the grid.

![](/uploads/acgo/image/73c001d8aa4825b0_760bc67ae623.jpeg)
上一题 去做题 下一题