4439: Chessboard Billiard棋盘式台球

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:4 通过:3

题目描述

C. Chessboard Billiard
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
让我们想象一下:有一个棋子台球。它的动作类似于主教棋子。唯一的区别是,当台球击中棋盘的边界时,它可以从中反射并继续移动。


更正式地说,选择四个对角方向中的第一个,台球沿该方向移动。
当它到达位于棋盘边缘的正方形时,台球会从中反射;它将其移动方向改变90度并继续移动。
具体来说,当台球到达角隅时,它会被反射两次,并开始向相反方向移动。当台球运动时,它可以进行无限次数的反射。
台球在其轨迹的任何一个正方形处都可以停止,移动即视为完成。


如果a能够到达b所在的点,则认为一个台球a击败另一个台球b。
建议您找到台球的最大数量,成对的台球不会互相击败,并且可以放置在n×m大小的棋盘上。
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.
Input
The first line contains two integers n and m (2≤n,m≤106).
Output
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).
Examples
Input
3 4
Output
2
Input
3 3
Output
3


输入格式

第一行包含两个整数n和m(2 ≤ n, m ≤ 106)。

输出格式

打印一个单一的数字,即不成对击败对方的台球的最大可能数量。

输入样例 复制

3 4

输出样例 复制

2