結果

問題 No.751 Frac #2
ユーザー x87asdfx87asdf
提出日時 2018-11-14 18:10:58
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 987 bytes
コンパイル時間 2,909 ms
コンパイル使用メモリ 76,052 KB
実行使用メモリ 58,984 KB
最終ジャッジ日時 2023-08-26 01:09:47
合計ジャッジ時間 9,507 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
56,716 KB
testcase_01 AC 150 ms
56,780 KB
testcase_02 WA -
testcase_03 AC 151 ms
56,824 KB
testcase_04 AC 149 ms
56,616 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 152 ms
56,720 KB
testcase_08 WA -
testcase_09 AC 151 ms
56,936 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 150 ms
56,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 152 ms
56,752 KB
testcase_19 AC 152 ms
56,760 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 151 ms
56,824 KB
testcase_33 AC 154 ms
56,652 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

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