eolymp
bolt
Try our new interface for solving problems
Problems

Queen of angle 2

Queen of angle 2

In the lower left corner of the board \textbf{M×N} is the queen. Two players take turns walking the queen, moving it to any number of cells vertically upwards, horizontally to the right, or diagonally to the right and upwards. You need to put the queen in the upper right corner. Plays one who could not make a move, respectively, is considered the winning opponent. Determine how much for the first player for a given board there is a losing position. \InputFile Input data consist of a set of input data. Each row is set to the size of the board - two positive integers \textbf{M} and \textbf{N}, not exceeding \textbf{1000}. Queries end with a line containing two zeros. \OutputFile The program shall for each request on a separate line to bring a single number - the number of losing positions for the first player.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
3 4
0 0
Output example #1
3