eolymp
bolt
Try our new interface for solving problems
Problems

Bishops on a Toral Board

Bishops on a Toral Board

A bishop is a chess piece that can move in any diagonal direction to any number of cells. Imagine that we take a board of a size \textbf{m}х\textbf{n} and connect its top and bottom edges, and its left and right edges, so that it would have a form of a torus. For example, on a \textbf{7}×\textbf{10} board the neighbours of a cell \textbf{(4, 1)} would be \textbf{(3, 10)}, \textbf{(3, 1)}, \textbf{(3, 2)}, \textbf{(4, 10)}, \textbf{(4, 2)}, \textbf{(5, 10)}, \textbf{(5, 1)}, \textbf{(5, 2)}; the neighbours of a cell \textbf{(1, 10)} - \textbf{(7, 9)}, \textbf{(7, 10)}, \textbf{(7, 1)}, \textbf{(1, 9)}, \textbf{(1, 1)},\textbf{(2, 9)}, \textbf{(2, 10)}, \textbf{(2, 1)}. On a toral board chess pieces are no longer limited with the edges, and, for example, on a \textbf{7}×\textbf{10} board a bishop from any cell can move to any other cell of the board in one turn, say, from cell \textbf{(2, 1)} to cell \textbf{(7, 9)} by a path \textbf{(2, 1)} → \textbf{(1, 10) }→ \textbf{(7, 9)}. Let us say that a set of bishops covers the board if one can move some bishop to any free cell in one turn. In other words, each cell is either occupied or threatened by some bishop. Your task is to find out what is the minimal number of bishops one needs to cover the \textbf{m}×\textbf{n} toral board. \InputFile Input file contains \textbf{m} and \textbf{n} separated by a space (\textbf{1} ≤ \textbf{n}, \textbf{m} ≤ \textbf{10^100}). \OutputFile Output the minimal number of bishops needed to cover the \textbf{m}×\textbf{n} toral board.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2 2
Output example #1
2
Source 2004 Petrozavodsk, Summer, Andrew Stankevich Contest 7, August 22, Problem I