10265 - I2P homework8   

Description

The input is a sequence of positive fractions e.g. 1/2, 2/3, 3/4, and the output is their sum expressed also as a simple fraction, which is 23/12 in this case. Note that the answer should be expressed in simplest terms, for example,  the output of 1/3 plus 1/6 should be displayed as 1/2 not 3/6. If the answer is an integer then the denominator should be 1, for example, the output of 1/2 plus 1/2 should be 1/1.
Note that the input may not be simple fractions.

hints:
1. Calculate the least common multiple of the denominators.
2. You may implement the following two functions for computing the greatest common divisor and the least common multiple:

int gcd(int a, int b);
int lcm(int a, int b);

Input

The first line is an integer N (0 The next N lines contain the N positive fractional numbers, represented as a pair of numerator and denominator.  The numerators and the denominators are two-digit numbers (smaller than 100).

Output

The output is a pair of numerator and denominator, ended with a newline character.

Sample Input  Download

Sample Output  Download

Tags




Discuss