Fractions!    [1998 Greater New York ACM contest]

Filename: fractions.cc

For this problem, we will number the fractions strictly between zero and one precisely as follows:

1.   1/2
2.   1/3
3.   2/3
4.   1/4
5.   2/4
6.   3/4
7.   1/5
8.   2/5
9.   3/5
10.  4/5
11.  1/6
12.  2/6
13.  3/6
14.  4/6

and so on, the "halves" first, then the "thirds," the "fourths," and so on. Each fraction appears in all of its equivalent forms (like 2/3, 4/6, 6/9, ...).

Your job is to add two fractions given by their positions in this list, giving as your answer the position of their sum in lowest terms. You may assume that the input values will correspond to fractions with denominators less than 100, and you may also assume that their sum will appear in this list.

INPUT: Two integers per line, representing the positions of two fractions in this list.

OUTPUT: One integer, the position in this list of the sum of the two fractions in lowest terms.


Example I/O:

Input File:

  2 13
  4 3

Output File:

  15
  66