結果

問題 No.751 Frac #2
ユーザー 37zigen37zigen
提出日時 2018-11-09 20:49:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 164 ms / 1,000 ms
コード長 1,134 bytes
コンパイル時間 4,239 ms
コンパイル使用メモリ 86,448 KB
実行使用メモリ 55,168 KB
最終ジャッジ日時 2024-05-01 04:19:03
合計ジャッジ時間 9,372 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
55,080 KB
testcase_01 AC 153 ms
54,856 KB
testcase_02 AC 154 ms
55,112 KB
testcase_03 AC 159 ms
54,876 KB
testcase_04 AC 150 ms
54,876 KB
testcase_05 AC 153 ms
54,616 KB
testcase_06 AC 152 ms
55,040 KB
testcase_07 AC 155 ms
54,940 KB
testcase_08 AC 154 ms
55,168 KB
testcase_09 AC 157 ms
54,884 KB
testcase_10 AC 155 ms
54,964 KB
testcase_11 AC 154 ms
55,024 KB
testcase_12 AC 152 ms
55,040 KB
testcase_13 AC 152 ms
54,872 KB
testcase_14 AC 152 ms
55,132 KB
testcase_15 AC 153 ms
54,820 KB
testcase_16 AC 155 ms
54,760 KB
testcase_17 AC 158 ms
55,160 KB
testcase_18 AC 149 ms
54,500 KB
testcase_19 AC 140 ms
54,672 KB
testcase_20 AC 151 ms
54,860 KB
testcase_21 AC 156 ms
54,804 KB
testcase_22 AC 151 ms
54,972 KB
testcase_23 AC 151 ms
54,884 KB
testcase_24 AC 147 ms
54,960 KB
testcase_25 AC 149 ms
54,824 KB
testcase_26 AC 149 ms
54,940 KB
testcase_27 AC 154 ms
54,744 KB
testcase_28 AC 158 ms
54,848 KB
testcase_29 AC 155 ms
54,984 KB
testcase_30 AC 151 ms
54,860 KB
testcase_31 AC 148 ms
54,876 KB
testcase_32 AC 149 ms
55,036 KB
testcase_33 AC 151 ms
54,832 KB
testcase_34 AC 164 ms
55,060 KB
testcase_35 AC 153 ms
54,836 KB
testcase_36 AC 151 ms
54,884 KB
testcase_37 AC 150 ms
54,908 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