結果

問題 No.751 Frac #2
ユーザー 37zigen37zigen
提出日時 2018-11-09 20:49:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 158 ms / 1,000 ms
コード長 1,134 bytes
コンパイル時間 3,098 ms
コンパイル使用メモリ 85,256 KB
実行使用メモリ 43,544 KB
最終ジャッジ日時 2023-08-13 10:59:33
合計ジャッジ時間 12,166 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
43,544 KB
testcase_01 AC 145 ms
40,924 KB
testcase_02 AC 147 ms
40,572 KB
testcase_03 AC 146 ms
40,592 KB
testcase_04 AC 147 ms
40,392 KB
testcase_05 AC 146 ms
40,712 KB
testcase_06 AC 147 ms
40,392 KB
testcase_07 AC 150 ms
40,540 KB
testcase_08 AC 158 ms
40,184 KB
testcase_09 AC 157 ms
40,256 KB
testcase_10 AC 148 ms
40,696 KB
testcase_11 AC 147 ms
40,192 KB
testcase_12 AC 149 ms
40,384 KB
testcase_13 AC 150 ms
40,716 KB
testcase_14 AC 148 ms
40,204 KB
testcase_15 AC 147 ms
40,720 KB
testcase_16 AC 148 ms
40,596 KB
testcase_17 AC 146 ms
40,284 KB
testcase_18 AC 146 ms
40,500 KB
testcase_19 AC 145 ms
40,488 KB
testcase_20 AC 147 ms
40,376 KB
testcase_21 AC 146 ms
40,628 KB
testcase_22 AC 144 ms
40,156 KB
testcase_23 AC 148 ms
40,844 KB
testcase_24 AC 150 ms
40,504 KB
testcase_25 AC 150 ms
40,424 KB
testcase_26 AC 152 ms
40,548 KB
testcase_27 AC 149 ms
40,480 KB
testcase_28 AC 148 ms
40,904 KB
testcase_29 AC 147 ms
40,800 KB
testcase_30 AC 146 ms
40,220 KB
testcase_31 AC 144 ms
40,248 KB
testcase_32 AC 143 ms
40,440 KB
testcase_33 AC 147 ms
40,836 KB
testcase_34 AC 152 ms
40,280 KB
testcase_35 AC 149 ms
40,172 KB
testcase_36 AC 149 ms
40,244 KB
testcase_37 AC 145 ms
40,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

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 den = 1;
		long num = 1;
		for (int i = n2 - 1; i >= 0; i -= 2) {
			if (n2 % 2 == 1) {
				den = den * B[i];
			} else {
				num = num * B[i];
			}
		}
		for (int i = n2 - 2; i >= 0; i -= 2) {
			if (n2 % 2 == 0) {
				den = den * B[i];
			} else {
				num = num * B[i];
			}
		}
		for (int i = 1; i < n1; ++i) {
			den = den * A[i];
		}
		num *= A[0];
		long g = gcd(Math.abs(den), Math.abs(num));
		den /= g;
		num /= g;
		System.out.println((int) (Math.signum(num) * Math.signum(den)) * Math.abs(num) + " " + Math.abs(den));
	}

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

	public static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0