Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<algorithm>
- using namespace std;
- void addFraction(int num1, int den1, int num2,int den2){
- long long int gcd = __gcd(den1, den2);
- long long int lcm = ((den1*den2)/ gcd);
- long long int upper_half = ((lcm / den1)* num1+(lcm / den2)* num2);
- //upper_half /= gcd;
- //lcm /= gcd;
- if(upper_half % 2 == 0 && lcm % 2 == 0){
- upper_half /= 2;
- lcm /= 2;
- }
- cout << upper_half << '/' << lcm << endl;
- }
- int main(){
- int t; cin >> t;
- while(t--){
- int a, b, c, d;
- cin >> a >> b >> c >> d;
- addFraction(a, b, c, d);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement