Problem E - Fractions, fractions, fractions

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/6
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 on the same 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.

Scanned and beautified by onTy Toom,