結果

問題 No.751 Frac #2
コンテスト
ユーザー htensai
提出日時 2019-12-10 01:13:12
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
WA  
実行時間 -
コード長 1,015 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,708 ms
コンパイル使用メモリ 83,504 KB
実行使用メモリ 48,160 KB
最終ジャッジ日時 2026-03-08 05:52:07
合計ジャッジ時間 6,091 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;

public class Main {
   public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n1 = sc.nextInt();
        long child = sc.nextInt();
        long mother = 1;
        for (int i = 1; i < n1; i++) {
            mother *= sc.nextInt();
        }
        int n2 = sc.nextInt();
        mother *= sc.nextInt();
        for (int i = 1; i < n2; i++) {
            child *= sc.nextInt();
        }
        boolean isPlus = true;
        if (child < 0) {
            isPlus = false;
            child *= -1;
        }
        if (mother < 0) {
            isPlus = !isPlus;
            mother *= -1;
        }
        long d = gcd(child, mother);
        child /= d;
        mother /= d;
        if (!isPlus) {
            child *= -1;
        }
        System.out.println(child + " " + mother);
    }
    
    static long gcd(long x, long y) {
        if (x % y == 0) {
            return y;
        } else {
            return gcd(y, x % y);
        }
    }
}
0