CF74C.Chessboard Billiard

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.

More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed.

It is considered that one billiard ball a beats another billiard ball b if a can reach a point where b is located.

You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard n × m in size.

我们来想象一种“国际象棋棋子式台球”:它的移动方式类似于国际象棋中的象(主教),唯一不同之处在于,当该台球碰到棋盘边界时,可以发生反射并继续运动。

更严格地描述如下:首先选定四个对角线方向之一,台球即沿该方向运动。当它到达位于棋盘边缘的格子时,会发生反射——其运动方向改变 90∘90^\circ,然后继续运动。特别地,若它抵达一个角上的格子,则发生两次反射,并开始朝完全相反的方向运动。在运动过程中,台球可进行无限次反射。在轨迹上的任意一个格子处,台球均可停止,此时该步移动即告完成。

定义:若台球 aa 能够到达台球 bb 所在的位置,则称台球 aa 击败台球 bb。

请找出在 n×mn \times m 大小的棋盘上,所能放置的、两两互不击败的台球的最大数目。

输入格式

The first line contains two integers n and m (2 ≤ n, m ≤ 106).

第一行包含两个整数 nn 和 mm(2 ≤ n, m ≤ 1062 \leq n, m \leq 10^6)。

输出格式

Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other.

Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).

输出一个整数,即互不“击败”对方的台球的最大可能数量。

在 C++ 中,请勿使用 %lld 格式说明符读取或写入 64 位整数。推荐使用 cin(也可使用 %I64d 格式说明符)。

输入输出样例

  • 输入#1

    3 4

    输出#1

    2
  • 输入#2

    3 3

    输出#2

    3

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

首页