-
Notifications
You must be signed in to change notification settings - Fork 0
/
phanso.c
37 lines (37 loc) · 928 Bytes
/
phanso.c
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
#include <stdio.h>
int UCLN(int a, int b)
{
if (b == 0)
return a;
return UCLN(b, a % b);
}
int main()
{
int t, c = 1;
scanf("%d", &t);
while (t--)
{
printf("Case #%d:\n", c);
int pt, pm, qt, qm;
scanf("%d%d%d%d", &pt, &pm, &qt, &qm);
int a = pt, b = pm, e = qt, d = qm;
pt = pt / UCLN(a, b);
pm = pm / UCLN(a, b);
qt = qt / UCLN(e, d);
qm = qm / UCLN(e, d);
int mau, tu1, tu2, tu3, tu4, mau4;
mau = pm * qm / UCLN(pm, qm);
tu1 = pt * mau / pm;
tu2 = qt * mau / qm;
printf("%d/%d %d/%d\n", tu1, mau, tu2, mau);
tu3 = tu1 + tu2;
int m = tu3;
tu3 = tu3 / UCLN(m, mau);
mau = mau / UCLN(m, mau);
printf("%d/%d\n", tu3, mau);
tu4 = tu1 / UCLN(tu1, tu2);
mau4 = tu2 / UCLN(tu1, tu2);
printf("%d/%d\n", tu4, mau4);
c++;
}
}