#include <stdio.h>

// 求最大公约数 int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); }

int main() { int n; scanf("%d", &n);

long long int numerator = 1;  // 分子
long long int denominator = 1;  // 分母

for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    
    // 求当前分式的最大公约数
    int g = gcd(a, b);
    
    // 分子和分母分别乘以当前分式的最大公约数
    numerator *= a / g;
    denominator *= b / g;
    
    // 求最终结果的最大公约数
    g = gcd(numerator, denominator);
    
    // 分子和分母同时除以最大公约数,得到最简形式
    numerator /= g;
    denominator /= g;
}

// 如果分母为1,则结果为整数,直接输出分子
if (denominator == 1) {
    printf("%lld\n", numerator);
} else {
    printf("%lld/%lld\n", numerator, denominator);
}

return 0;

}


原文地址: https://www.cveoy.top/t/topic/dp3k 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录