HDU 1713 相遇周期 (最小公倍数)
题意:。。。
析:求周期就是这两个分数的最小公倍数,可以先通分,再计算分子的最小倍数。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int main(){
int T; cin >> T;
while(T--){
LL a, b, c, d;
scanf("%lld/%lld", &a, &b);
scanf("%lld/%lld", &c, &d);
LL tmp = b / __gcd(b, d) * d;
a = a * (tmp / b);
c = c * (tmp / d);
LL t = a / __gcd(a, c) * c;
LL x = __gcd(t, tmp);
t /= x;
tmp /= x;
if(1 == tmp) cout << t << endl;
else cout << t << "/" << tmp << endl;
}
return 0;
}
HDU 1713 相遇周期 (最小公倍数)的更多相关文章
- hdu 1713 相遇周期
求分数的最小公倍数.对于a/b c/d 先化简为最简分数,分数最小公倍数=分子的最小公倍数/分母的最大公约数. ;}
- 杭电ACM 1713 相遇周期
相遇周期 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 1713 最小公倍数与最大公约数的问题 相遇周期
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) 相遇周期 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/ ...
- 杭电oj_1713——相遇周期(java实现)
question:相遇周期 思路: 首先将两个分数化为最简形式(也就是分子分母同时除以最大公约数) 然后题意是要求两个分数的最小公倍数 借助以下两个公式,就可以求出结果 1.最小公倍数*最大公约数 = ...
- hdu 1713求分数的最小公倍数
题意中的圈数和天数说反了 #include<stdio.h> __int64 gcd(__int64 a,__int64 b) {/* 比如4/3 3/5 通分20/15 9/15 所以这 ...
- hdu 相遇周期
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int ...
- HDU 1005(周期问题)
HDU 1005 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descript ...
- HDU 1222 - Wolf and Rabbit & HDU 1108 - [最大公约数&最小公倍数]
水题,只是想借此记一下gcd函数的模板 #include<cstdio> int gcd(int m,int n){return n?gcd(n,m%n):m;} int main() { ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
随机推荐
- Android4.42-Setting源代码分析之蓝牙模块Bluetooth(下)
接着上一篇Android4.42-Settings源代码分析之蓝牙模块Bluetooth(上) 继续蓝牙模块源代码的研究 THREE.蓝牙模块功能实现 switch的分析以及本机蓝牙重命名和可见性的分 ...
- Unity ----- 对象池GameObjectPool
孙广东 2014.6.28 非常早之前看到的外国文章,认为不错,分享一下. 对象池在AssetStore中也是有非常多插件的,可是有些重了.自己写一个轻量的岂不是非常好. 当你须要创建大量某种类型对象 ...
- hdoj-3371-Connect the Cities【最小生成树】
Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- typedef和#define的差别——————【Badboy】
typedef 和#define 都经常使用来定义一个标识符及keyword的别名.但他们之间有关键的差别. typedef 是语言编译过程的一部分; #define是宏定义语句,它本身并不在编译过程 ...
- MCE----Machine-check exception
http://en.wikipedia.org/wiki/Machine_Check_Exception Machine-check exception From Wikipedia, the fre ...
- 程序员笔记|Spring IoC、面向切面编程、事务管理等Spring基本概念详解
一.Spring IoC 1.1 重要概念 1)控制反转(Inversion of control) 控制反转是一种通过描述(在java中通过xml或者注解)并通过第三方去产生或获取特定对象的方式. ...
- 浅谈JavaScript的函数表达式(闭包)
前文已经简单的介绍了函数的闭包.函数的闭包就是有权访问另一个函数作用域的函数,也就是函数内部又定义了一个函数. var Super=function(num){ var count=num; retu ...
- 4408: [Fjoi 2016]神秘数
4408: [Fjoi 2016]神秘数 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 452 Solved: 273 [Submit][Stat ...
- XFire WebService demo
XFire创建WebService实例应用 XFire使得在JavaEE应用中发布Web服务变得轻而易举.和其他Web服务引擎相比, XFire的配置非常简单,可以非常容易地和Spring集成. ...
- SpringMVC配置环境
一,lib目录下加入spring一般所需的jar包 二,配置web.xml <?xml version="1.0" encoding="UTF-8"?&g ...