WC '98 P6 - Return of the Plachta

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 16M

Problem type
Woburn Challenge 1998

Han Solo (who is a pilot), having handily beaten Three Thumbs Plachta at bowling is talking to some friends at a bar. Here, he recounts a tale of the legendary driver known only as "Forth-and-back" Plachta. He tells of a day when she was driving a bunch of students down in a foreign land known as the United States. Unsatisfied with the posted speed limit of 70 mph, Ms. Plachta makes the calculations to prepare her van for the jump to hyperspace. Of course, everyone knows that this is a difficult task and some complicated calculations need to be made, including the adding of fractions. You will help her make the jump to light speed because, obviously, you want to live. All you have to do is add 2 fractions together and return the resulting fraction in reduced form.

Input Specification

4 numbers separated by spaces representing respectively \text{numerator}_1, \text{denominator}_1, \text{numerator}_2, \text{denominator}_2. Each of the input numbers will be in the range 0 \le \text{numerator} \le 32\,000 or 0 < \text{denominator} \le 32\,000. There will be 5 such inputs, ie. 5 sets of fractions to add.

Output Specification

Add the 2 fractions on each line together and return the reduced fraction (one line for each set). If the reduced fraction is a whole number, you should output it as a whole number and not as a fraction.

Sample Input

2 3 4 5
2 3 5 6
1 2 1 2
24000 1 24000 2
0 2 0 5

Sample Output

22 15
3 2
1
36000
0

Sample Explanation

In the first set of fractions, \frac{2}{3} + \frac{4}{5} = \frac{22}{15}.
In the second set of fractions, \frac{2}{3} + \frac{5}{6} = \frac{3}{2}.
In the third set of fractions, \frac{1}{2} + \frac{1}{2} = 1.
In the fourth set of fractions, \frac{24\,000}{1} + \frac{24\,000}{2} = 36\,000.
In the fifth set of fractions, \frac{0}{2} + \frac{0}{5} = 0.


Comments

There are no comments at the moment.