10294 - Lab08   

Description

The input is a sequence of positive fractions, e.g., 1/2, 2/3, 3/4. To get the output, let the first fraction minus the sum of the others, which is -11/12 in this case.
Note that the answer should be expressed in simplest terms, for example,  the output of 8/4 minus 3/2 should be displayed as 1/2 not 2/4.
If the answer is an integer then the denominator should be 1, for example, the output of 3/2 minus 1/2 should be 1/1.
Furthermore, if the answer is negative, add a symbol '-' at the beginning of the output.
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