結果

問題 No.751 Frac #2
ユーザー 👑 CleyL
提出日時 2020-02-27 15:38:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 717 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 64,032 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-13 15:57:28
合計ジャッジ時間 1,381 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
template <typename T>
T gcd(T a,T b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
int main(){
    long long S = 1;
    long long B = 1;
    int a;cin>>a;
    for(int i = 0; a > i; i++){
        long long t;cin>>t;
        if(i){
            B *= t;
        }else{
            S *= t;
        }
    }
    cin>>a;
    for(int i = 0; a > i; i++){
        long long t;cin>>t;
        if(i%2){
            S *= t;
        }else{
            B *= t;
        }
    }
    if(((S/gcd(S,B) < 0) + (B/gcd(S,B) < 0)) % 2){
        cout << "-" << abs(S/gcd(S,B)) << " " << abs(B/gcd(S,B)) << endl;
    }else{
        cout << abs(S/gcd(S,B)) << " " << abs(B/gcd(S,B)) << endl;
    }
}
0