HDU 相遇周期
来源:互联网 发布:淘宝银行卡怎么解绑 编辑:程序博客网 时间:2024/05/16 01:18
HDU -
相遇周期
/*Problem :相遇周期Author : herongweiLanguage : G++CreateTime: 2016/01/11*//*解析:两周期分别为a/b、c/d,既然是相遇周期,就是最早什么时间相遇,也就是两者的最小公倍数,转化一下,也就是求LCM(a, c)/ gcd(b, d)。直接求即可,不一定要用long long 或者 __int64,int也能过。注意:先把a/b和c/d尽可能的化简再求。*/#include <math.h>#include <queue>#include <deque>#include <vector>#include <stack>#include <stdio.h>#include <ctype.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>using namespace std;#define Max(a,b) a>b?a:b#define Min(a,b) a>b?b:a#define mem(a,b) memset(a,b,sizeof(a))int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};const double eps = 1e-6;const double Pi = acos(-1.0);static const int inf= 0x3f3f3f3f;static const int maxn = 1e5+10;typedef long long LL;int m, n;char ss[1005][1005];typedef pair<int, int> P;int ans[1003];int cnt;int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}int lcm(int a,int b){ return a/gcd(a,b)*b;}int main(){ // freopen("1.txt","r",stdin); int t; scanf("%d",&t); while(t--) { int a1,b1,a2,b2; scanf("%d/%d %d/%d",&a1,&b1,&a2,&b2); int g1=gcd(a1,b1); int g2=gcd(a2,b2); a1/=g1;b1/=g1; a2/=g2;b2/=g2; int c1=lcm(a1,a2); int c2=gcd(b1,b2); int c3; if(c1%c2==0) printf("%d\n",c1/c2); else { int g3=gcd(c1,c2); c1/=g3; c2/=g3; printf("%d/%d\n",c1,c2); } } return 0;}
0 0
- HDU 1713 相遇周期
- HDU - 1713 相遇周期
- hdu 相遇周期
- HDU 1713 相遇周期
- HDU 1713 相遇周期
- HDU 1713 相遇周期
- HDU 1713 相遇周期
- HDU 1713 -相遇周期
- HDU-1713 相遇周期
- HDU-1713 相遇周期
- HDU 相遇周期
- Hdu 1713 相遇周期
- 关于HDU 1713 相遇周期
- HDU 2.1.3 相遇周期
- hdu acmsteps 2-1-3相遇周期
- HDU1713--相遇周期 HDU(110)
- hdu 1713 相遇周期 (GCD & LCM)
- 相遇周期
- Android 操作SQLite基本用法介绍
- Lua & C 交互 3 c/c++调用lua
- android studio的assets目录下存放ttf字体格式的问题
- JavaWeb学习总结(一)——JavaWeb开发入门
- 学习shell编程笔记(二)
- HDU 相遇周期
- Android应用程序互保方案
- android异步加载之Handler、AsyncTask(一)
- Android studio正确配置AndroidAnnotation注解
- leetcode-326-Power of Three
- ASP.NET第一部分总结
- 将软键盘的回车按钮变为搜索按钮
- 作为一场新的挑战。
- Java JSON库Jackson 2.x新变化一览