本文主要是介绍求两个分数的最小公倍数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include<stdio.h>
long long gcd(long long a, long long b)
{return a % b == 0? b:gcd(b, a%b);
}void remove(long long &a, long long &b)
{long long tmp = a > b?gcd(a, b):gcd(b, a);a = a/tmp;b = b/tmp;
}int main()
{long long n, a, b, c, d;scanf("%lld", &n);while(n--){scanf("%lld/%lld %lld/%lld", &a, &b, &c, &d);remove(a, b);remove(c, d);long long fenzi = (a*c)/gcd(a, c);long long fenmu = gcd(b,d); if(fenzi%fenmu){printf("%lld/%lld\n", fenzi, fenmu);}elseprintf("%lld\n", fenzi/fenmu);}return 0;
}
这篇关于求两个分数的最小公倍数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!