結果

問題 No.751 Frac #2
ユーザー x87asdfx87asdf
提出日時 2018-11-14 18:02:37
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 833 bytes
コンパイル時間 2,213 ms
コンパイル使用メモリ 73,196 KB
実行使用メモリ 59,020 KB
最終ジャッジ日時 2023-08-26 01:09:12
合計ジャッジ時間 9,809 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
56,804 KB
testcase_01 AC 152 ms
56,700 KB
testcase_02 WA -
testcase_03 AC 151 ms
56,860 KB
testcase_04 AC 150 ms
56,468 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 150 ms
56,648 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 151 ms
56,628 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 152 ms
56,620 KB
testcase_19 AC 149 ms
56,372 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 149 ms
56,736 KB
testcase_33 AC 152 ms
56,620 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);
        int n1 = 0;
        int a1 = 1;
        int a2 = 1;

        int n2 = 0;
        int b1 = 1;
        int b2 = 1;

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

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

        a1 *= b2;
        a2 *= b1;

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

        System.out.println(a1+" "+a2);
        
    }
    static int calculateGcf(int m, int n) {
    	int s = 0;
    	while(m % n != 0) {
    		s = m;
    		m = n;
    		n = s % n;
    	}

    	return n;
    }
}
0