結果

問題 No.751 Frac #2
ユーザー Mcpu3Mcpu3
提出日時 2018-12-20 21:16:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 146 ms / 1,000 ms
コード長 682 bytes
コンパイル時間 3,457 ms
コンパイル使用メモリ 81,812 KB
実行使用メモリ 58,500 KB
最終ジャッジ日時 2023-10-26 01:12:39
合計ジャッジ時間 11,107 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
58,352 KB
testcase_01 AC 141 ms
58,288 KB
testcase_02 AC 139 ms
58,352 KB
testcase_03 AC 138 ms
58,292 KB
testcase_04 AC 145 ms
58,384 KB
testcase_05 AC 141 ms
58,296 KB
testcase_06 AC 137 ms
58,296 KB
testcase_07 AC 140 ms
58,356 KB
testcase_08 AC 141 ms
57,792 KB
testcase_09 AC 136 ms
58,188 KB
testcase_10 AC 144 ms
57,756 KB
testcase_11 AC 145 ms
58,464 KB
testcase_12 AC 139 ms
58,348 KB
testcase_13 AC 141 ms
58,344 KB
testcase_14 AC 143 ms
58,288 KB
testcase_15 AC 135 ms
57,904 KB
testcase_16 AC 132 ms
57,432 KB
testcase_17 AC 145 ms
58,296 KB
testcase_18 AC 143 ms
58,156 KB
testcase_19 AC 144 ms
58,164 KB
testcase_20 AC 144 ms
58,184 KB
testcase_21 AC 132 ms
57,908 KB
testcase_22 AC 138 ms
56,264 KB
testcase_23 AC 141 ms
58,356 KB
testcase_24 AC 143 ms
58,500 KB
testcase_25 AC 143 ms
58,480 KB
testcase_26 AC 143 ms
58,356 KB
testcase_27 AC 146 ms
58,320 KB
testcase_28 AC 141 ms
58,352 KB
testcase_29 AC 132 ms
57,904 KB
testcase_30 AC 144 ms
56,480 KB
testcase_31 AC 144 ms
58,352 KB
testcase_32 AC 144 ms
58,288 KB
testcase_33 AC 142 ms
57,768 KB
testcase_34 AC 134 ms
57,908 KB
testcase_35 AC 141 ms
58,312 KB
testcase_36 AC 143 ms
56,408 KB
testcase_37 AC 145 ms
58,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Scanner;

class Main {
	public static long gcd(long a, long b) {
		return b != 0 ? gcd(b, a % b) : Math.abs(a);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		long A = sc.nextLong(), B = 1, tmp;
		for (int i = 1; i < n; ++i) B *= sc.nextLong();
		n = sc.nextInt();
		for (int i = 0; i < n; ++i) {
			if (i % 2 == 0) B *= sc.nextLong();
			else A *= sc.nextLong();
		}
		sc.close();
		if (B < 0) {
			A = -A;
			B = -B;
		}
		tmp = gcd(A, B);
		pw.print(A / tmp + " " + B / tmp);
		pw.close();
	}
}
0