結果

問題 No.1731 Product of Subsequence
ユーザー tamatotamato
提出日時 2021-11-05 21:53:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,393 ms / 2,000 ms
コード長 924 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 82,512 KB
実行使用メモリ 90,648 KB
最終ジャッジ日時 2024-04-25 17:20:34
合計ジャッジ時間 14,183 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,135 ms
89,448 KB
testcase_01 AC 38 ms
54,072 KB
testcase_02 AC 38 ms
52,644 KB
testcase_03 AC 40 ms
58,092 KB
testcase_04 AC 39 ms
53,940 KB
testcase_05 AC 43 ms
59,852 KB
testcase_06 AC 46 ms
62,096 KB
testcase_07 AC 40 ms
59,184 KB
testcase_08 AC 87 ms
76,244 KB
testcase_09 AC 45 ms
62,408 KB
testcase_10 AC 1,393 ms
89,996 KB
testcase_11 AC 1,137 ms
86,924 KB
testcase_12 AC 49 ms
62,644 KB
testcase_13 AC 106 ms
76,880 KB
testcase_14 AC 1,002 ms
85,344 KB
testcase_15 AC 37 ms
52,796 KB
testcase_16 AC 38 ms
53,068 KB
testcase_17 AC 39 ms
53,428 KB
testcase_18 AC 915 ms
84,300 KB
testcase_19 AC 107 ms
76,708 KB
testcase_20 AC 778 ms
81,660 KB
testcase_21 AC 1,380 ms
88,816 KB
testcase_22 AC 53 ms
65,508 KB
testcase_23 AC 46 ms
63,788 KB
testcase_24 AC 77 ms
71,552 KB
testcase_25 AC 63 ms
68,372 KB
testcase_26 AC 294 ms
77,188 KB
testcase_27 AC 370 ms
77,176 KB
testcase_28 AC 643 ms
79,140 KB
testcase_29 AC 311 ms
77,092 KB
testcase_30 AC 1,191 ms
90,648 KB
testcase_31 AC 52 ms
65,648 KB
testcase_32 AC 44 ms
62,756 KB
testcase_33 AC 53 ms
65,560 KB
testcase_34 AC 179 ms
76,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    from math import gcd
    input = sys.stdin.readline

    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    div = []
    for d in range(1, K+1):
        if d * d > K:
            break
        if K % d == 0:
            div.append(d)
            div.append(K // d)
    if div[-1] == div[-2]:
        div.pop()

    dp = {}
    dp[1] = 1
    for a in A:
        dp_new = {}
        for j in dp:
            if j not in dp_new:
                dp_new[j] = 0
            dp_new[j] = (dp_new[j] + dp[j])%mod
            j_new = gcd(j * a, K)
            if j_new not in dp_new:
                dp_new[j_new] = 0
            dp_new[j_new] = (dp_new[j_new] + dp[j])%mod
        dp = dp_new
    if K not in dp:
        dp[K] = 0
    if K == 1:
        dp[K] -= 1
        dp[K] %= mod
    print(dp[K])


if __name__ == '__main__':
    main()
0