-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1735.cpp
49 lines (36 loc) · 883 Bytes
/
1735.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
//반복문 이용하여 최대공약수(gcd) 구하기
int getGcdIter(int a, int b) {
int tmp;
while (b != 0) {
tmp = a % b;
a = b;
b = tmp;
}
return a;
}
vector<int> add(int a1, int a2, int b1, int b2) {
int numerator; //분자
int denominator; //분모
numerator = a1*b2 + a2*b1;
denominator = b1 * b2;
int gcd = getGcdIter(numerator, denominator);
denominator /= gcd;
numerator /= gcd;
vector<int> v = {numerator, denominator};
return v;
}
int main() {
//입출력 속도 향상
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a1, a2, b1, b2;
cin >> a1 >> b1;
cin >> a2 >> b2;
vector<int> v = add(a1, a2, b1, b2);
cout << v[0] << " " << v[1];
}