HDU 相遇周期
2016-01-11 23:25
295 查看
HDU -
相遇周期
/* Problem :相遇周期 Author : herongwei Language : 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; }
相关文章推荐
- SpringMVC @RequestBody接收Json对象字符串
- 类似QQ侧滑菜单功能实现
- 第四十四天-Apache虚拟主机测试
- 【iCore3 双核心板】例程三十:U_DISK_IAP_FPGA实验——更新升级FPGA
- JavaWeb学习总结(一)——JavaWeb开发入门
- opencv 提取曲线并用矩形框框出来
- 基于 zepto 的触摸函数封装
- 基于 zepto 的触摸函数封装
- 耕耘
- SpringMVC+Json构建基于Restful风格的应用
- CentOS(Linux)下如何安装源码包
- leetcode-326-Power of Three
- MongoDB安装、管理工具、操作
- Camera Function - 摄像头功能说明
- CocoaPods的下载和安装及常见问题
- jQuery 核心
- Java JSON库Jackson 2.x新变化一览
- 编译php7遇到的内存不足
- Android 操作SQLite基本用法介绍
- 作为一场新的挑战。