結果

問題 No.751 Frac #2
ユーザー chocopuu
提出日時 2018-11-10 20:32:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 937 bytes
コンパイル時間 1,641 ms
コンパイル使用メモリ 168,472 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-25 00:00:17
合計ジャッジ時間 2,804 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=1000000007;
const int INF=1e18;
int gcd(int x,int y){if(x==0)return y;return gcd(y%x,x);}
int lcm(int x, int y){return(x*y/gcd(x, y));}

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

    int A = 1,B = 1;
    int cnt = 0;

    int N;
    std::cin >> N ;
    for(int i = 0 ; i < N ; i++){
        int x;
        std::cin >> x ;
        if (x<0)
        {
            cnt++;
        }
        if (i==0) {
            A*=x;
        } else {
            B*=x;
        }
    }
    int M;
    std::cin >> M ;
    for(int i = 0 ; i < M ; i++){
        int x;
        std::cin >> x ;
        if (x<0)
        {
            cnt++;
        }
        if (i%2==0) {
            B*=x;
        } else {
            A*=x;
        }
    }
    int x=gcd(abs(A),abs(B));

    std::cout << abs(A)/x*(pow(-1,(cnt%2))) <<" " <<abs(B)/x << "\n";
    return 0;
}
0