結果

問題 No.1731 Product of Subsequence
ユーザー puznekopuzneko
提出日時 2021-11-20 01:20:27
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 966 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 86,804 KB
最終ジャッジ日時 2023-08-07 23:41:43
合計ジャッジ時間 7,678 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 420 ms
86,436 KB
testcase_01 AC 72 ms
70,956 KB
testcase_02 AC 71 ms
71,084 KB
testcase_03 AC 75 ms
75,556 KB
testcase_04 AC 72 ms
71,264 KB
testcase_05 AC 81 ms
76,536 KB
testcase_06 AC 80 ms
76,060 KB
testcase_07 AC 75 ms
75,648 KB
testcase_08 AC 101 ms
76,356 KB
testcase_09 AC 78 ms
76,540 KB
testcase_10 AC 432 ms
86,720 KB
testcase_11 AC 372 ms
86,472 KB
testcase_12 AC 91 ms
76,680 KB
testcase_13 AC 92 ms
76,688 KB
testcase_14 AC 361 ms
85,972 KB
testcase_15 AC 71 ms
70,976 KB
testcase_16 AC 72 ms
70,920 KB
testcase_17 AC 72 ms
71,092 KB
testcase_18 AC 421 ms
86,804 KB
testcase_19 AC 94 ms
76,644 KB
testcase_20 AC 360 ms
86,508 KB
testcase_21 AC 431 ms
86,688 KB
testcase_22 AC 83 ms
76,460 KB
testcase_23 AC 78 ms
76,352 KB
testcase_24 AC 93 ms
76,472 KB
testcase_25 AC 90 ms
76,524 KB
testcase_26 AC 133 ms
76,688 KB
testcase_27 AC 154 ms
76,704 KB
testcase_28 AC 260 ms
85,780 KB
testcase_29 AC 138 ms
76,556 KB
testcase_30 AC 423 ms
86,364 KB
testcase_31 AC 82 ms
76,304 KB
testcase_32 AC 77 ms
76,196 KB
testcase_33 AC 79 ms
76,252 KB
testcase_34 AC 100 ms
76,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from sys import stdin
n, m, *a = map(int, stdin.read().split())
p = 10**9+7

divideset = set()
for i in range(1,int(math.floor(math.sqrt(m)))+2):
    if m % i == 0:
        divideset.add(i)
        divideset.add(m//i)

dividelist = list(divideset)
dividelist.sort()
dividedict = dict()
nd = len(dividelist)
for i in range(nd):
    dividedict[dividelist[i]] = i

check = True
for i in range(n):
    kari = math.gcd(a[i],m)
    a[i] = kari
    if kari != m:
        check = False
if check:
    ans = 1
    for i in range(n):
        ans = ans * 2 % p
    ans = (ans - 1) % p
    print("{}".format(ans))
    exit()

dp = [[0 for i in range(nd)] for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
    for j in range(nd):
        kari = a[i] * dividelist[j]
        val = math.gcd(kari,m)
        dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % p
        dp[i+1][dividedict[val]] = (dp[i+1][dividedict[val]] + dp[i][j]) % p

ans = dp[n][nd-1]
print("{}".format(ans))
0