結果

問題 No.751 Frac #2
ユーザー x87asdf
提出日時 2018-11-15 17:16:02
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 897 bytes
コンパイル時間 2,080 ms
コンパイル使用メモリ 78,928 KB
実行使用メモリ 42,664 KB
最終ジャッジ日時 2024-12-24 13:58:51
合計ジャッジ時間 9,069 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {

	static Scanner sc;
	static long numerator;
	static long denominator;

	public static void main(String[] args) {

		sc = new Scanner(System.in);
		numerator = 1;
		denominator = 1;

		inputNume(sc.nextInt());
		inputDeno(sc.nextInt());

		long gcf = calculateGcf(numerator, denominator);
		numerator /= gcf;
		denominator /= gcf;

		System.out.println(numerator+" "+denominator);
	}

	static void inputNume(int l) {
		numerator *= sc.nextLong();
		for(int i=1;i<l;i++) {
			denominator *= sc.nextInt();
		}
	}

	static void inputDeno(int l) {
		for(int i=0;i<l;i++) {
			if(i % 2 != 0) {
				numerator *= sc.nextLong();
			} else {
				denominator *= sc.nextLong();
			}
		}
	}

	static long calculateGcf(long m, long n) {
		if(m == 0 || n == 0) {
			return 1;
		}
		long s = 0;
		while(m % n != 0) {
			s = m;
			m = n;
			n = s % n;
		}
		return n;
	}
}
0