-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathk.cpp
More file actions
47 lines (34 loc) · 714 Bytes
/
k.cpp
File metadata and controls
47 lines (34 loc) · 714 Bytes
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
#include <iostream>
#include <stdio.h>
int mmc(int num1, int num2) {
int resto, a, b;
a = num1;
b = num2;
do {
resto = a % b;
a = b;
b = resto;
} while (resto != 0);
return ( num1 * num2) / a;
}
int mdc(int a, int b){
int z = -1;
while (z !=0){
z = a % b;
a = b;
b = z;
}
return a;
}
int main() {
int a,b,c,d, fmmc;
scanf("%d %d %d %d", &a, &b, &c, &d);
if (b == d) {
printf("%d %d\n", (a+c)/mdc(a+c, d), d/mdc(a+c, d));
}else{
fmmc = mmc(b, d);
a = (fmmc/b) * a;
c = (fmmc/d) * c;
printf("%d %d\n",(a+c)/mdc(a+c, fmmc), fmmc/mdc(a+c, fmmc));
}
}