天天看點

???題目7 : Bounce

題目7 : Bounce

時間限制: 1000ms 單點時限: 1000ms 記憶體限制: 256MB

描述

For Argo, it is very interesting watching a circle bouncing in a rectangle.

As shown in the figure below, the rectangle is divided into N×M grids, and the circle fits exactly one grid.

The bouncing rule is simple:

1. The circle always starts from the left upper corner and moves towards lower right.

2. If the circle touches any edge of the rectangle, it will bounce.

3. If the circle reaches any corner of the rectangle after starting, it will stop there.

???題目7 : Bounce
Argo wants to know how many grids the circle will go through only once until it first reaches another corner. Can you help him?

輸入

The input consists of multiple test cases. (Up to 105)

For each test case:

One line contains two integers N and M, indicating the number of rows and columns of the rectangle. (2 ≤ N, M ≤ 109)

輸出

For each test case, output one line containing one integer, the number of grids that the circle will go through exactly once until it stops (the starting grid and the ending grid also count).

樣例輸入

2 2
2 3
3 4
3 5
4 5
4 6
4 7
5 6
5 7
9 15      
樣例輸出
2
3
5
5
7
8
7
9
11
39      

比賽已經結束,去題庫送出。