結果

問題 No.751 Frac #2
ユーザー Mcpu3Mcpu3
提出日時 2018-08-30 02:19:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 151 ms / 1,000 ms
コード長 918 bytes
コンパイル時間 2,205 ms
コンパイル使用メモリ 78,928 KB
実行使用メモリ 42,832 KB
最終ジャッジ日時 2024-04-20 15:20:34
合計ジャッジ時間 8,857 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
42,452 KB
testcase_01 AC 142 ms
42,440 KB
testcase_02 AC 143 ms
42,280 KB
testcase_03 AC 146 ms
42,032 KB
testcase_04 AC 137 ms
42,152 KB
testcase_05 AC 140 ms
42,388 KB
testcase_06 AC 147 ms
42,160 KB
testcase_07 AC 131 ms
42,196 KB
testcase_08 AC 142 ms
42,312 KB
testcase_09 AC 151 ms
42,732 KB
testcase_10 AC 141 ms
42,440 KB
testcase_11 AC 122 ms
42,308 KB
testcase_12 AC 137 ms
42,456 KB
testcase_13 AC 139 ms
42,404 KB
testcase_14 AC 150 ms
42,320 KB
testcase_15 AC 149 ms
42,300 KB
testcase_16 AC 138 ms
42,512 KB
testcase_17 AC 141 ms
42,712 KB
testcase_18 AC 131 ms
42,364 KB
testcase_19 AC 142 ms
42,300 KB
testcase_20 AC 139 ms
42,516 KB
testcase_21 AC 135 ms
42,180 KB
testcase_22 AC 132 ms
42,444 KB
testcase_23 AC 129 ms
42,648 KB
testcase_24 AC 140 ms
42,396 KB
testcase_25 AC 134 ms
42,312 KB
testcase_26 AC 146 ms
42,552 KB
testcase_27 AC 131 ms
42,508 KB
testcase_28 AC 137 ms
42,732 KB
testcase_29 AC 126 ms
42,832 KB
testcase_30 AC 123 ms
41,908 KB
testcase_31 AC 136 ms
42,568 KB
testcase_32 AC 124 ms
42,636 KB
testcase_33 AC 138 ms
42,300 KB
testcase_34 AC 126 ms
42,368 KB
testcase_35 AC 138 ms
42,396 KB
testcase_36 AC 137 ms
42,136 KB
testcase_37 AC 127 ms
42,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main
{
	public static long gcd(long x, long y)
	{
		long r;
		x = Math.abs(x);
		y = Math.abs(y);
		if (y > x) {
			r = x;
			x = y;
			y = r;
		}
		while (y > 0) {
			r = x % y;
			x = y;
			y = r;
		}
		return x;
	}
	
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		long n1, n2, a, b, numerator = 0, denominator = 1, i;
		n1 = sc.nextInt();
		for (i = 0; i < n1; i++) {
			a = sc.nextInt();
			if (1 > i) numerator = a;
			else denominator *= a;
		}
		n2 = sc.nextInt();
		for (i = 0; i < n2; i++) {
			b = sc.nextInt();
			if (i % 2 == 1) numerator *= b;
			else denominator *= b;
		}
		sc.close();
		if (0 > denominator) {
			numerator = -numerator;
			denominator = -denominator;
		}
		System.out.print(numerator / gcd(numerator, denominator) + " " + denominator / gcd(numerator, denominator));
	}
}
0