ACMSTEP 2.1.3 相遇周期 //数论 分数的最小公倍数
2011-08-11 11:33
447 查看
原题链接 同题:HDU 1713
输入c1/t1 c2/t2 ,也就是速度的分数形式,转换成:c1*t2/(t1*t2), c2*t1/( t1*t2 );
需要求出分子的最小公倍数k,然后k/( t1*t2 )就是题目求的周期
注意用 __int64, 否则WA
输入c1/t1 c2/t2 ,也就是速度的分数形式,转换成:c1*t2/(t1*t2), c2*t1/( t1*t2 );
需要求出分子的最小公倍数k,然后k/( t1*t2 )就是题目求的周期
注意用 __int64, 否则WA
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <vector> #include <queue> #include <algorithm> using namespace std; __int64 gcd(__int64 a,__int64 b) { if (!a || !b) return a>b?a:b; for (int t; t = x% y; x =y; y = t); return y; } int main() { int t; __int64 a,b,c,d; cin>>t; while(t--) { scanf("%I64d/%I64d%I64d/%I64d",&a,&b,&c,&d); a=a*d*c*b/gcd(a*d,c*b); b=b*d; if(a%b) { c=gcd(a,b); printf("%I64d/%I64d\n",a/c,b/c); } else printf("%I64d\n",a/b); } return 0; }
相关文章推荐
- HDOJ ACMstep 2.1.3 相遇周期
- HDU 1713 相遇周期(求两个分数的最小公倍数)
- HDU 2.1.3 相遇周期
- HDU 1713相遇周期(两个分数的lcm)
- hdu_2.1.3_相遇周期
- (Relax 数论 1.17)POJ 3101 Astronomy(分数的最小公倍数)
- HDU 1713 相遇周期 LCD LCM 2.1.3
- ACMSTEP 2.1.1 最小公倍数 //数论
- 2.1.3 相遇周期(lcm、gcd的使用)
- Astronomy poj 3101 数论 分数的最小公倍数 Cherish the memory of my broken heart
- ACMSTEP 2.1.8 小数化分数 2 //数论 数学 没AC
- HDU 1713 相遇周期 — 欧几里得算法与最大公约数,最小公倍数
- HDOJ---ACMSteps---2.1.3相遇周期
- HDU2.1.3 相遇周期
- HDU 1713 相遇周期【这也算数学吗?】
- hrbust 1328 相等的最小公倍数(数论)
- 51nod 1355 斐波那契的最小公倍数 (数论+莫比乌斯反演)
- 3101 Astronomy Java大数,分数的最小公倍数
- hdu 1108 最小公倍数(数论基础 水)
- 【数论】【最大公约数】【枚举约数】CODEVS 1012 最大公约数和最小公倍数问题 2001年NOIP全国联赛普及组