結果

問題 No.1731 Product of Subsequence
ユーザー tentententen
提出日時 2021-11-08 12:58:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,137 ms / 2,000 ms
コード長 1,877 bytes
コンパイル時間 2,378 ms
コンパイル使用メモリ 78,600 KB
実行使用メモリ 70,640 KB
最終ジャッジ日時 2024-04-25 17:48:40
合計ジャッジ時間 15,169 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 719 ms
67,220 KB
testcase_01 AC 50 ms
50,484 KB
testcase_02 AC 51 ms
50,492 KB
testcase_03 AC 49 ms
50,376 KB
testcase_04 AC 50 ms
50,568 KB
testcase_05 AC 58 ms
50,448 KB
testcase_06 AC 61 ms
50,336 KB
testcase_07 AC 54 ms
50,444 KB
testcase_08 AC 171 ms
55,368 KB
testcase_09 AC 107 ms
51,696 KB
testcase_10 AC 1,047 ms
67,732 KB
testcase_11 AC 972 ms
69,472 KB
testcase_12 AC 105 ms
51,712 KB
testcase_13 AC 186 ms
56,412 KB
testcase_14 AC 684 ms
67,164 KB
testcase_15 AC 51 ms
50,276 KB
testcase_16 AC 49 ms
49,936 KB
testcase_17 AC 53 ms
50,084 KB
testcase_18 AC 1,137 ms
70,640 KB
testcase_19 AC 182 ms
55,952 KB
testcase_20 AC 677 ms
67,160 KB
testcase_21 AC 1,035 ms
69,540 KB
testcase_22 AC 112 ms
52,072 KB
testcase_23 AC 110 ms
51,812 KB
testcase_24 AC 161 ms
56,216 KB
testcase_25 AC 122 ms
54,336 KB
testcase_26 AC 412 ms
63,880 KB
testcase_27 AC 464 ms
67,108 KB
testcase_28 AC 579 ms
67,156 KB
testcase_29 AC 409 ms
65,088 KB
testcase_30 AC 824 ms
68,284 KB
testcase_31 AC 103 ms
52,012 KB
testcase_32 AC 96 ms
51,876 KB
testcase_33 AC 109 ms
51,956 KB
testcase_34 AC 279 ms
59,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        HashMap<Integer, Integer> counts = new HashMap<>();
        
        for (int i = 0; i < n; i++) {
            int x = getGCD(sc.nextLong(), k);
            HashMap<Integer, Integer> next = new HashMap<>();
            for (int y : counts.keySet()) {
                int z = getGCD((long)x * y, k);
                next.put(z, (next.getOrDefault(z, 0) + counts.get(y)) % MOD);
            }
            for (int y : next.keySet()) {
                counts.put(y, (counts.getOrDefault(y, 0) + next.get(y)) % MOD);
            }
            counts.put(x, (counts.getOrDefault(x, 0) + 1) % MOD);
        }
        System.out.println(counts.getOrDefault(k, 0));
    }
    
    static int getGCD(long x, long y) {
        if (x % y == 0) {
            return (int)y;
        } else {
            return getGCD(y, x % y);
        }
    }
    
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0