結果

問題 No.751 Frac #2
ユーザー 37zigen37zigen
提出日時 2018-11-09 20:52:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 153 ms / 1,000 ms
コード長 1,442 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 76,268 KB
実行使用メモリ 40,856 KB
最終ジャッジ日時 2023-08-13 10:59:53
合計ジャッジ時間 9,455 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
40,396 KB
testcase_01 AC 150 ms
40,644 KB
testcase_02 AC 149 ms
40,336 KB
testcase_03 AC 150 ms
40,544 KB
testcase_04 AC 151 ms
40,768 KB
testcase_05 AC 150 ms
40,528 KB
testcase_06 AC 144 ms
40,636 KB
testcase_07 AC 146 ms
40,800 KB
testcase_08 AC 151 ms
40,852 KB
testcase_09 AC 147 ms
40,672 KB
testcase_10 AC 146 ms
40,496 KB
testcase_11 AC 147 ms
40,208 KB
testcase_12 AC 143 ms
40,636 KB
testcase_13 AC 148 ms
40,508 KB
testcase_14 AC 147 ms
40,844 KB
testcase_15 AC 148 ms
40,268 KB
testcase_16 AC 153 ms
40,396 KB
testcase_17 AC 146 ms
40,720 KB
testcase_18 AC 143 ms
40,160 KB
testcase_19 AC 146 ms
40,628 KB
testcase_20 AC 144 ms
40,256 KB
testcase_21 AC 143 ms
40,468 KB
testcase_22 AC 144 ms
40,452 KB
testcase_23 AC 147 ms
40,856 KB
testcase_24 AC 143 ms
40,272 KB
testcase_25 AC 147 ms
40,576 KB
testcase_26 AC 144 ms
40,572 KB
testcase_27 AC 146 ms
40,572 KB
testcase_28 AC 145 ms
40,376 KB
testcase_29 AC 151 ms
40,228 KB
testcase_30 AC 147 ms
40,284 KB
testcase_31 AC 147 ms
40,392 KB
testcase_32 AC 142 ms
40,236 KB
testcase_33 AC 143 ms
40,380 KB
testcase_34 AC 147 ms
40,372 KB
testcase_35 AC 146 ms
40,552 KB
testcase_36 AC 150 ms
40,484 KB
testcase_37 AC 145 ms
40,372 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();
		if (!(1 <= n1 && n1 <= 10))
			throw new AssertionError();
		long[] A = new long[n1];
		for (int i = 0; i < n1; ++i) {
			A[i] = sc.nextLong();
			if (!(1 <= Math.abs(A[i]) && Math.abs(A[i]) <= 10))
				throw new AssertionError();
		}
		int n2 = sc.nextInt();
		if (!(1 <= n2 && n2 <= 10))
			throw new AssertionError();
		long[] B = new long[n2];
		for (int i = 0; i < n2; ++i) {
			B[i] = sc.nextLong();
			if (!(1 <= Math.abs(B[i]) && Math.abs(B[i]) <= 10))
				throw new AssertionError();
		}
		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