Queen of angle 2
In the lower left corner of the board 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.
Input
Input data consist of a set of input data. Each row is set to the size of the board - two positive integers M and N, not exceeding 1000. Queries end with a line containing two zeros.
Output
The program shall for each request on a separate line to bring a single number - the number of losing positions for the first player.