fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct ps
  5. {
  6. long long tu, mau;
  7. };
  8.  
  9. void rutgon(ps &x)
  10. {
  11. if(x.mau<0)
  12. {
  13. x.mau = -x.mau;
  14. x.tu = -x.tu;
  15. }
  16. long long tam = __gcd(x.tu, x.mau);
  17. x.tu/=tam, x.mau/=tam;
  18. }
  19.  
  20. ps cong(ps x, ps y)
  21. {
  22. ps t;
  23. t.mau = x.mau*y.mau;
  24. t.tu = x.tu*y.mau + x.mau*y.tu;
  25. rutgon(t);
  26. return t;
  27. }
  28.  
  29. int main()
  30. {
  31. ps x, y, t;
  32. cin >> x.tu >> x.mau;
  33. cin >> y.tu >> y.mau;
  34. rutgon(x);
  35. rutgon(y);
  36. t = cong(x, y);
  37. rutgon(t);
  38. cout << t.tu << ' ' << t.mau;
  39. }
  40.  
Success #stdin #stdout 0.01s 5288KB
stdin
1 2
1 3
stdout
5 6