結果
| 問題 | 
                            No.751 Frac #2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             htensai
                         | 
                    
| 提出日時 | 2019-12-10 01:13:12 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,015 bytes | 
| コンパイル時間 | 2,430 ms | 
| コンパイル使用メモリ | 76,484 KB | 
| 実行使用メモリ | 56,864 KB | 
| 最終ジャッジ日時 | 2024-06-23 11:38:49 | 
| 合計ジャッジ時間 | 9,555 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 9 WA * 27 | 
ソースコード
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);
        }
    }
}
            
            
            
        
            
htensai