CF1725A.Accumulation of Dominoes

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Pak Chanek has a grid that has NN rows and MM columns. Each row is numbered from 11 to NN from top to bottom. Each column is numbered from 11 to MM from left to right.

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

  • Row 11 contains integers from 11 to MM from left to right.
  • Row 22 contains integers from M+1M+1 to 2×M2 \times M from left to right.
  • Row 33 contains integers from 2×M+12 \times M+1 to 3×M3 \times M from left to right.
  • And so on until row NN.

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 11. 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.

帕克·查内克有一个 NN 行 MM 列的网格。各行从上到下编号为 11 至 NN,各列从左到右编号为 11 至 MM。

网格中每个格子包含一个数字,这些数字按如下方式排列:

  • 第 11 行从左到右依次为整数 11 至 MM;
  • 第 22 行从左到右依次为整数 M+1M+1 至 2×M2 \times M;
  • 第 33 行从左到右依次为整数 2×M+12 \times M+1 至 3×M3 \times M;
  • 依此类推,直至第 NN 行。

一个“多米诺骨牌”(domino)定义为网格中两个相邻(即共享一条边)的不同格子。当且仅当这两个格子中的数字之差的绝对值恰好为 11 时,该多米诺骨牌被称为“紧凑的”(tight)。请计算网格中不同的紧凑多米诺骨牌的总数。

当且仅当存在至少一个格子属于其中一个多米诺骨牌但不属于另一个时,称这两个多米诺骨牌是不同的。

输入格式

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

唯一一行包含两个整数 NN 和 MM(1≤N,M≤1091 \leq N, M \leq 10^9)—— 分别表示网格的行数和列数。

输出格式

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.

The picture below is an example of a tight domino in the grid.

下图是 Pak Chanek 在第一个样例中所拥有的网格。

下图是该网格中一个紧凑多米诺骨牌(tight domino)的示例。

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

首页