Chessboard Billiard

题意翻译

一天,有一个神犇无聊(太无聊了吧= =),发明了一种新玩具:**象棋弹球** 象棋弹球在一个棋盘上沿斜线移动(类似象棋中的象),更厉害的是,当球到达棋盘边上的格子时会反弹,也就是将移动方向改变90度(如图)。当球到达棋盘的一角时,它会将移动方向改变180度(如图)。一个弹球在移动时,会反弹无数次。当完成了一个运动周期后(即弹球又重复了同样的路),弹球可以选择在任意的位置停止运动。 一个棋盘上可以放置许多个象棋弹球。放置一个弹球时,你可以选择它的初始运动方向(左上45度,左下45度,右上45度,右下45度)待它停止运动,你可以放置下一个弹球。弹球运动时,不能碰到先前停止运动的弹球,也就是它的运动轨迹不能经过先前停止运动的弹球所在的格子。 棋盘有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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF74C/2b32b43a6cf594e055f4f908960d44aaa5bece14.png)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.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ m $ ( $ 2<=n,m<=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).

输入输出样例

输入样例 #1

3 4

输出样例 #1

2

输入样例 #2

3 3

输出样例 #2

3