結果

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

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n1 = 0;
        long a1 = 1;
        long a2 = 1;

        long n2 = 0;
        long b1 = 1;
        long b2 = 1;

        n1 = sc.nextLong();
        a1 = sc.nextLong();
        for(long i=1;i<n1;i++) {
        	a2 *= sc.nextLong();
        }

        n2 = sc.nextLong();
        b1 = sc.nextLong();
        for(long i=1;i<n2;i++) {
        	b2 *= sc.nextLong();
        }

        a1 *= b2;
        a2 *= b1;

        long gcf = calculateGcf(a1, a2);
        a1 /= gcf;
        a2 /= gcf;

        if(a1 < 0&&a2 < 0) {
        	a1*=-1;
        	a2*=-1;
        } else if(a1 >= 0&&a2 < 0){
        	a1*=-1;
        	a2*=-1;
        }

        System.out.println(a1+" "+a2);
    }

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