D. Problem D. Fractionstellar

题目链接

https://nanti.jisuanke.com/t/44337

#include <iostream>
#include <malloc.h>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <cstring>
#define IO                       \
    ios::sync_with_stdio(false); \
    // cin.tie(0);                  \
    // cout.tie(0);
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const double PI = 3.14159;
const double eps = 1e-8;
LL gcd(LL a, LL b)
{
    return b == 0 ? a : gcd(b, a % b);
}
LL a, b, c, d, n;
LL a1, b1, c1, d1;
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    IO;
    LL T;
    cin >> T;
    while (T--)
    {
        cin >> a >> b >> c >> d;
        a1 = a, b1 = b, c1 = c, d1 = d;
        LL g1 = gcd(a, b);
        LL g2 = gcd(c, d);
        a /= g1;
        b /= g1;
        c /= g2;
        d /= g2;
        LL g3 = gcd(a, c);
        LL g4 = gcd(b, d);
        LL lcm_ac = a / g3 * c;
        LL lcm_bd = b / g4 * d;
        LL x1, y1, x2, y2;
        x1 = g3;
        y1 = lcm_bd;
        x2 = lcm_ac;
        y2 = g4;
        LL g5 = gcd(x1, y1);
        LL g6 = gcd(x2, y2);
        x1 /= g5;
        x2 /= g5;
        x2 /= g6;
        y2 /= g6;
        cout << x1 << "/" << y1 << " " << x2 << "/" << y2 << endl;
    }
    return 0;
}

1、开LL

2、lcm 先乘再除

3.不知道为什么先通分为啥不对

发布了81 篇原创文章 · 获赞 29 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_44115065/article/details/104996559