### Woburn Challenge 1998

## Episode 6: Return of the Plachta

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 70mph, 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

4 numbers separated by spaces representing respectively numerator1, denominator1, numerator2, denominator2. Each of the input numbers will be in the range 0 ≤ numerator ≤ 32000 or 0 < denominator ≤ 32000. There will be 5 such inputs, ie. 5 sets of fractions to add.

### Output

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`

(ie. ^{2}/

_{3}+

^{4}/

_{5})

`2 3 5 6 `

(ie. ^{2}/

_{3}+

^{5}/

_{6})

`1 2 1 2 `

(ie. ^{1}/

_{2}+

^{1}/

_{2})

`24000 1 24000 2`

0 2 0 5

### Sample Output

` 22 15 `

(ie. ^{22}/

_{15})

`3 2 `

(ie. ^{3}/

_{2})

1 36000 0

All Submissions

Best Solutions

**Point Value:** 10

**Time Limit:** 2.00s

**Memory Limit:** 16M

**Added:** Sep 29, 2008

**Languages Allowed:**

C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

## Comments (Search)

Thinkdifferenton Jan 11, 2012 - 12:16:47 am UTCis this because my program is too slow?

jargonon Jan 11, 2012 - 12:26:50 am UTC Re: ...bobbyg212009on Nov 04, 2011 - 9:02:42 pm UTCtime error

Danielon Nov 05, 2011 - 12:02:54 am UTC Re: ...Did you try extreme test cases on your computer?

(Remember that the numerator and denominator can go up to 32000)

purohit3105on Jan 01, 2009 - 3:42:23 am UTC Whats wrong?It calculates the samples properly??

bleung91on Jan 01, 2009 - 4:00:21 am UTC Re: Whats wrong?bbi5291on Jan 01, 2009 - 4:21:12 am UTC Re: Re: Whats wrong?purohit3105on Jan 01, 2009 - 5:28:16 am UTC Re: Re: Re: Whats wrong?bleung91on Jan 01, 2009 - 5:48:37 am UTC Re: Re: Re: Re: Whats wrong?http://en.wikipedia.org/wiki/Euclidean_algorithm

I refer you here, because this is the best way to do this problem.

purohit3105on Jan 01, 2009 - 10:26:42 pm UTC Re: Re: Re: Re: Re: Whats wrong?hansonw1on Jan 01, 2009 - 10:31:58 pm UTC Re: Whats wrong?Look at your output, and the sample output, and the difference should be clear.

Bobon Dec 30, 2008 - 6:24:42 pm UTC what's wrong with my program?bbi5291on Dec 30, 2008 - 8:35:35 pm UTC Re: what's wrong with my program?Bobon Dec 31, 2008 - 1:24:16 am UTC Re: Re: what's wrong with my program?hansonw1on Nov 15, 2008 - 6:01:17 pm UTC Hintbleung91on Dec 31, 2008 - 12:53:27 am UTC Re: Hinthansonw1on Dec 31, 2008 - 1:21:23 am UTC Re: HintHelloMelloon Nov 15, 2008 - 5:26:39 pm UTC Fast TimesdAedaLon Nov 15, 2008 - 5:43:36 pm UTC ?