結果

問題 No.736 約比
ユーザー masamasa
提出日時 2019-01-11 15:25:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 1,437 bytes
コンパイル時間 1,673 ms
コンパイル使用メモリ 74,144 KB
実行使用メモリ 56,632 KB
最終ジャッジ日時 2023-08-19 02:31:30
合計ジャッジ時間 12,510 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
55,688 KB
testcase_01 AC 111 ms
56,012 KB
testcase_02 AC 119 ms
55,912 KB
testcase_03 AC 118 ms
55,820 KB
testcase_04 AC 117 ms
56,552 KB
testcase_05 AC 105 ms
56,104 KB
testcase_06 AC 103 ms
55,904 KB
testcase_07 AC 124 ms
56,084 KB
testcase_08 AC 127 ms
55,840 KB
testcase_09 AC 123 ms
55,912 KB
testcase_10 AC 121 ms
56,016 KB
testcase_11 AC 123 ms
56,064 KB
testcase_12 AC 123 ms
56,416 KB
testcase_13 AC 122 ms
56,096 KB
testcase_14 AC 114 ms
56,096 KB
testcase_15 AC 118 ms
56,284 KB
testcase_16 AC 114 ms
56,192 KB
testcase_17 AC 125 ms
55,832 KB
testcase_18 AC 124 ms
56,132 KB
testcase_19 AC 116 ms
56,124 KB
testcase_20 AC 118 ms
55,680 KB
testcase_21 AC 116 ms
56,432 KB
testcase_22 AC 103 ms
55,976 KB
testcase_23 AC 103 ms
55,748 KB
testcase_24 AC 120 ms
55,696 KB
testcase_25 AC 114 ms
55,676 KB
testcase_26 AC 104 ms
55,816 KB
testcase_27 AC 121 ms
56,436 KB
testcase_28 AC 130 ms
56,016 KB
testcase_29 AC 102 ms
56,060 KB
testcase_30 AC 120 ms
55,448 KB
testcase_31 AC 104 ms
55,764 KB
testcase_32 AC 104 ms
56,344 KB
testcase_33 AC 121 ms
56,164 KB
testcase_34 AC 104 ms
56,036 KB
testcase_35 AC 103 ms
56,208 KB
testcase_36 AC 119 ms
55,668 KB
testcase_37 AC 120 ms
55,916 KB
testcase_38 AC 118 ms
56,048 KB
testcase_39 AC 100 ms
55,948 KB
testcase_40 AC 120 ms
55,752 KB
testcase_41 AC 117 ms
55,764 KB
testcase_42 AC 116 ms
55,660 KB
testcase_43 AC 120 ms
56,460 KB
testcase_44 AC 119 ms
56,092 KB
testcase_45 AC 120 ms
55,956 KB
testcase_46 AC 111 ms
55,688 KB
testcase_47 AC 123 ms
56,360 KB
testcase_48 AC 114 ms
56,148 KB
testcase_49 AC 107 ms
56,048 KB
testcase_50 AC 109 ms
55,716 KB
testcase_51 AC 112 ms
56,312 KB
testcase_52 AC 122 ms
55,788 KB
testcase_53 AC 119 ms
55,888 KB
testcase_54 AC 116 ms
55,488 KB
testcase_55 AC 112 ms
56,632 KB
testcase_56 AC 114 ms
56,184 KB
testcase_57 AC 104 ms
55,776 KB
testcase_58 AC 121 ms
56,136 KB
testcase_59 AC 133 ms
56,276 KB
testcase_60 AC 111 ms
55,696 KB
testcase_61 AC 120 ms
56,076 KB
testcase_62 AC 104 ms
56,308 KB
testcase_63 AC 103 ms
56,008 KB
testcase_64 AC 104 ms
56,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    
    // ユークリッド互除法関数
    public static long gcd(long argA, long argB) {
        long a,b,r;
        a = argA;
        b = argB;

        if (a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        
        r = a % b;

        while (r > 0) {
            a = b;
            b = r;
            r = a % b;
        }
        
        return b;
    }
    
    public static void main(String[] args) throws Exception {

        Scanner sc  = new Scanner(System.in);
        int n       = sc.nextInt();
        long val[]  = new long[n];
        long gcf    = 0;
        long tmp    = 0;
        
        // テストケースの値を確保
        for (int i = 0; i < n; i++) {
            val[i] = sc.nextLong();
        }
        
        // 最大公約数を求める
        for (int i = 0; i < n; i++) {
            if (i + 1 < n) tmp = gcd(val[i], val[i + 1]);
            if (gcf == 0) gcf = tmp;
            if (gcf > tmp) gcf = tmp;
        }
        
        // 最大公約数の検証
        for (int i = 0; i < n; i++) {
            if (val[i] % gcf != 0) gcf = 1;
        }
        
        // 答えの出力
        for (int i = 0; i < n; i++) {
            System.out.print(val[i] / gcf);
            if (i != n - 1) {
                System.out.print(":");
            }
        }
        System.out.println();
    }
}
0