結果

問題 No.751 Frac #2
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-21 22:54:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 169 ms / 1,000 ms
コード長 969 bytes
コンパイル時間 2,242 ms
コンパイル使用メモリ 80,188 KB
実行使用メモリ 42,700 KB
最終ジャッジ日時 2024-04-18 10:10:15
合計ジャッジ時間 9,269 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
42,372 KB
testcase_01 AC 154 ms
42,500 KB
testcase_02 AC 147 ms
42,472 KB
testcase_03 AC 161 ms
42,568 KB
testcase_04 AC 154 ms
42,608 KB
testcase_05 AC 152 ms
42,664 KB
testcase_06 AC 149 ms
42,668 KB
testcase_07 AC 155 ms
42,412 KB
testcase_08 AC 147 ms
42,364 KB
testcase_09 AC 146 ms
42,272 KB
testcase_10 AC 142 ms
42,376 KB
testcase_11 AC 156 ms
42,388 KB
testcase_12 AC 133 ms
42,492 KB
testcase_13 AC 133 ms
42,572 KB
testcase_14 AC 169 ms
42,372 KB
testcase_15 AC 158 ms
42,684 KB
testcase_16 AC 153 ms
42,344 KB
testcase_17 AC 166 ms
42,428 KB
testcase_18 AC 155 ms
42,580 KB
testcase_19 AC 152 ms
42,544 KB
testcase_20 AC 143 ms
42,428 KB
testcase_21 AC 146 ms
42,576 KB
testcase_22 AC 159 ms
42,372 KB
testcase_23 AC 160 ms
42,516 KB
testcase_24 AC 143 ms
42,700 KB
testcase_25 AC 144 ms
42,668 KB
testcase_26 AC 145 ms
42,448 KB
testcase_27 AC 146 ms
42,520 KB
testcase_28 AC 165 ms
42,584 KB
testcase_29 AC 143 ms
42,368 KB
testcase_30 AC 159 ms
42,380 KB
testcase_31 AC 157 ms
42,392 KB
testcase_32 AC 162 ms
42,464 KB
testcase_33 AC 157 ms
42,204 KB
testcase_34 AC 156 ms
42,472 KB
testcase_35 AC 138 ms
42,664 KB
testcase_36 AC 160 ms
42,576 KB
testcase_37 AC 157 ms
42,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n1 = sc.nextInt();
    long[] a = new long[n1];
    for(int i = 0; i < n1; i++) {
      a[i] = sc.nextLong();
    }
    int n2 = sc.nextInt();
    long[] b = new long[n2];
    for(int i = 0; i < n2; i++) {
      b[i] = sc.nextLong();
    }
    long t1 = a[0];
    long t2 = 1;
    for(int i = 1; i < n1; i++) {
      t2 *= a[i]; 
    }
    for(int i = 0; i < n2; i++) {
      if(i % 2 == 0) {
        t2 *= b[i];        
      } else {
        t1 *= b[i];
      }
    }
    long s1 = Math.abs(t1);
    long s2 = Math.abs(t2);
    long g = gcd(s1, s2);
    long a1 = s1 / g;
    long a2 = s2 / g;
    if((t1) * (t2) > 0) {
      System.out.println(a1 + " " + a2);
    } else {
      System.out.println((-1) * a1 + " " + a2);
    }
  }

  public static long gcd(long a, long b) {
    if(b == 0) return a;
    return gcd(b, (a % b));
  }
}
0