Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using int64 = int64_t;
- using namespace std;
- int64 gcd(int64 a, int64 b){
- while (a != 0 && b != 0){
- if (a < b){
- swap(a, b);
- }
- a = a % b;
- }
- return b;
- }
- int main(){
- int64 a, b, c, d;
- cin >> a >> b >> c >> d;
- int GCD = gcd(d, b);
- int lcm = d * b/GCD;
- int num = (a*d + c*b)/GCD;
- int t = gcd(num, lcm);
- cout << num/t << " " << lcm/t;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement