結果

問題 No.917 Make One With GCD
ユーザー tentententen
提出日時 2020-12-02 10:34:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 3,671 ms
コンパイル使用メモリ 73,580 KB
実行使用メモリ 56,628 KB
最終ジャッジ日時 2023-10-11 04:52:22
合計ジャッジ時間 8,757 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
55,956 KB
testcase_01 AC 121 ms
56,348 KB
testcase_02 AC 122 ms
56,004 KB
testcase_03 AC 123 ms
56,336 KB
testcase_04 AC 123 ms
55,972 KB
testcase_05 AC 126 ms
55,872 KB
testcase_06 AC 131 ms
56,164 KB
testcase_07 AC 131 ms
56,628 KB
testcase_08 AC 127 ms
56,524 KB
testcase_09 AC 142 ms
56,352 KB
testcase_10 AC 141 ms
53,932 KB
testcase_11 AC 140 ms
55,812 KB
testcase_12 AC 142 ms
56,308 KB
testcase_13 AC 137 ms
56,404 KB
testcase_14 AC 140 ms
56,420 KB
testcase_15 AC 136 ms
56,512 KB
testcase_16 AC 135 ms
55,884 KB
testcase_17 AC 121 ms
56,240 KB
testcase_18 AC 131 ms
56,140 KB
testcase_19 AC 121 ms
56,080 KB
testcase_20 AC 124 ms
54,348 KB
testcase_21 AC 127 ms
56,156 KB
testcase_22 AC 125 ms
55,804 KB
testcase_23 AC 135 ms
55,888 KB
testcase_24 AC 131 ms
56,012 KB
testcase_25 AC 134 ms
56,160 KB
testcase_26 AC 121 ms
56,272 KB
testcase_27 AC 122 ms
56,252 KB
testcase_28 AC 121 ms
56,216 KB
testcase_29 AC 122 ms
56,156 KB
testcase_30 AC 123 ms
55,816 KB
testcase_31 AC 120 ms
56,440 KB
testcase_32 AC 121 ms
56,052 KB
testcase_33 AC 120 ms
56,292 KB
testcase_34 AC 121 ms
56,012 KB
testcase_35 AC 121 ms
55,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeMap<Integer, Long>  dp = new TreeMap<>();
        dp.put(sc.nextInt(), 1L);
        for (int i = 1; i < n; i++) {
            int x = sc.nextInt();
            Integer key = 0;
            while ((key = dp.higherKey(key)) != null) {
                int gcd = getGCD(key, x);
                dp.put(gcd, dp.getOrDefault(gcd, 0L) + dp.get(key));
            }
            dp.put(x, dp.getOrDefault(x, 0L) + 1L);
        }
        System.out.println(dp.getOrDefault(1, 0L));
    }
    
    static int getGCD(int x, int y) {
        if (x % y == 0) {
            return y;
        } else {
            return getGCD(y, x % y);
        }
    }
}
0