結果

問題 No.751 Frac #2
ユーザー mikianaaamikianaaa
提出日時 2020-09-15 14:09:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,203 bytes
コンパイル時間 1,535 ms
コンパイル使用メモリ 167,856 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-22 01:42:41
合計ジャッジ時間 2,178 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 6 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

long long GCD(long long a, long long b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int upp_bunshi = 0, upp_bunbo = 1;
    int low_bunshi = 0, low_bunbo = 1;

    int n1;
    cin >> n1;
    rep(i, n1) {
        int a;
        cin >> a;
        if (i == 0) {
            upp_bunshi = a;
        } else
            upp_bunbo *= a;
    }

    int n2;
    cin >> n2;
    rep(i, n2) {
        int a;
        cin >> a;
        if (i == 0) {
            low_bunshi = a;
        } else
            low_bunbo *= a;
    }

    int ans_bunshi = upp_bunshi * low_bunbo, ans_bunbo = upp_bunbo * low_bunshi;
    int gcd = GCD(abs(ans_bunbo), abs(ans_bunshi));
    ans_bunbo /= gcd, ans_bunshi /= gcd;
    if (ans_bunbo < 0 || ans_bunshi < 0) {
        ans_bunshi = -abs(ans_bunshi);
        ans_bunbo = abs(ans_bunbo);
    }
    cout << ans_bunshi << " " << ans_bunbo << endl;
}
0