#include <stdio.h>
/*ここを書く*/
struct fract {
int bunshi;
int bunbo;
};
int gcd(int m, int n)
{
int r;
if (m < n) return gcd(n, m); /* 常に m > n にしておく */
r = m % n; /* 余りrが.... */
if (r == 0) return n; /* 0 なら n がGCD */
return gcd(n, r); /* でなければnとrのGCD */
}
struct fract wa(struct fract a, struct fract b) {
a.bunshi = a.bunshi * b.bunbo + b.bunshi * a.bunbo;
a.bunbo *= b.bunbo;
return a;
}
struct fract seki(struct fract a, struct fract b) {
a.bunshi *= b.bunshi;
a.bunbo *= b.bunbo;
return a;
}
struct fract yakubun(struct fract a) {
int d;
d = gcd(a.bunshi, a.bunbo);
a.bunshi /= d;
a.bunbo /= d;
return a;
}
int main()
{
struct fract a1 = {1, 2}; /* 1/2を意味している */
struct fract a2 = {2, 3}; /* 2/3を意味している */
struct fract a3 = {3, 5}; /* 3/5を意味している */
struct fract a4 = {10, 3}; /* 10/3を意味している */
struct fract a5;
a5 = yakubun(seki(a3, seki(a4, wa(a3, wa(a1, a2)))));
printf("答:%d / %d \n", a5.
bunshi, a5.
bunbo); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovKuOBk+OBk+OCkuabuOOBjyovCnN0cnVjdCBmcmFjdCB7CiAgICBpbnQgYnVuc2hpOwogICAgaW50IGJ1bmJvOwp9OwoKaW50IGdjZChpbnQgbSwgaW50IG4pCnsKICAgIGludCByOwogICAgaWYgKG0gPCBuKSAgcmV0dXJuIGdjZChuLCBtKTsgLyog5bi444GrIG0gPiBuIOOBq+OBl+OBpuOBiuOBjyAgKi8KICAgIHIgPSBtICUgbjsgICAgICAgICAgICAgICAgICAgIC8qIOS9meOCinLjgYwuLi4uICAgICAgICAgICAgKi8KICAgIGlmIChyID09IDApIHJldHVybiBuOyAgICAgICAgIC8qIDAg44Gq44KJIG4g44GMR0NEICAgICAgICAgKi8KICAgIHJldHVybiBnY2Qobiwgcik7ICAgICAgICAgICAgIC8qIOOBp+OBquOBkeOCjOOBsG7jgahy44GuR0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