結果

問題 No.751 Frac #2
ユーザー Mcpu3
提出日時 2018-12-20 21:16:06
言語 Java
(openjdk 23)
結果
AC  
実行時間 179 ms / 1,000 ms
コード長 682 bytes
コンパイル時間 3,396 ms
コンパイル使用メモリ 84,440 KB
実行使用メモリ 55,176 KB
最終ジャッジ日時 2024-09-25 09:11:31
合計ジャッジ時間 11,094 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

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