SNGFRAC1 - Adding Two Fractions
Given two fractions, just add them. Too Easy :)
The fractions are represented either as p/q or p such that q >= 1. Now let p1/q1 and p2/q2 be the given fractions, then the sum of the fractions will either be P/Q or P (that allows the fraction to be in irreducible form).
The fraction given as p is equal to p/1.
Input
The first line of input is T, (total no. of test cases). Next T lines contains two space separated fractions.
Output
Print the sum of two fractions (must be in irreducible form) in most appropriate format in each line.
Example
Input: 5 1/2 1/3 2 -1/2 2/4 4/8 -1/7 1/11 -21/7 -31/1 Output: 5/6 3/2 1 -4/77 -34
Constraints
T <= 10000
-109 <= p <= 109
1 <= q <= 109
Irreducible Fraction
The fraction p/q is said to be in irreducible form if greatest common divisor of "p" and "q" is 1.
hide comments
|
Kanish_The_Vista:
2014-07-01 17:15:01
nice to solve by using C language......
|
|
Mitch Schwartz:
2014-06-22 15:26:03
Did you pull 2 seconds out of a hat?
|
|
AvmnuSng:
2014-06-22 12:02:55
All languages allowed and time limit is increased to 2 secs. So rejudge will be done.
|
|
Francky:
2014-06-22 12:02:55
Problem moved to tutorial as an interesting easy task. All languages should be allowed, and time limit should be increased to allow all languages to get AC with basic IO.
|
|
wisfaq:
2014-06-22 12:02:55
Adding two fractions and finding the result in lowest terms hardly is interesting, looks like gradeschool work.
|
|
Mitch Schwartz:
2014-06-22 12:02:55
@Abhimanyu Singh: Unfortunately, one of the issues from my perspective is that your responses/actions cause me to doubt whether you understand the issues that are being discussed.
|
|
Kanish_The_Vista:
2014-06-22 12:02:55
Finally Accepted Last edit: 2014-06-21 16:24:51 |
|
alex:
2014-06-22 12:02:55
@author:hey what is wrong in my submission:11800073
|
|
AvmnuSng:
2014-06-22 12:02:55
That's enough arguing... EB Members must do the needful regarding the problem.
|
|
Francky:
2014-06-22 12:02:55
@psetter : We very like when a problem is correctly (and fully) set at start, and we're allowing (requiring) changes when some troubles are present.
|
Added by: | AvmnuSng |
Date: | 2014-06-20 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | Abhimanyu Singh My Problems |