結果

問題 No.1731 Product of Subsequence
ユーザー mkawa2mkawa2
提出日時 2021-11-05 23:19:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,348 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 77,056 KB
最終ジャッジ日時 2024-04-24 07:18:38
合計ジャッジ時間 6,114 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 364 ms
76,800 KB
testcase_01 AC 39 ms
52,608 KB
testcase_02 AC 38 ms
52,096 KB
testcase_03 AC 41 ms
57,600 KB
testcase_04 AC 38 ms
52,096 KB
testcase_05 AC 49 ms
61,312 KB
testcase_06 AC 48 ms
61,184 KB
testcase_07 AC 44 ms
58,624 KB
testcase_08 AC 75 ms
76,288 KB
testcase_09 WA -
testcase_10 AC 386 ms
76,800 KB
testcase_11 AC 339 ms
76,672 KB
testcase_12 AC 56 ms
66,304 KB
testcase_13 AC 71 ms
76,416 KB
testcase_14 AC 309 ms
76,672 KB
testcase_15 AC 37 ms
52,608 KB
testcase_16 WA -
testcase_17 AC 38 ms
52,352 KB
testcase_18 AC 381 ms
77,056 KB
testcase_19 AC 71 ms
76,672 KB
testcase_20 AC 322 ms
76,544 KB
testcase_21 AC 404 ms
76,800 KB
testcase_22 AC 66 ms
68,608 KB
testcase_23 WA -
testcase_24 AC 72 ms
76,416 KB
testcase_25 AC 68 ms
76,672 KB
testcase_26 AC 123 ms
76,544 KB
testcase_27 AC 133 ms
76,416 KB
testcase_28 AC 217 ms
76,672 KB
testcase_29 AC 133 ms
76,416 KB
testcase_30 AC 327 ms
76,800 KB
testcase_31 AC 69 ms
68,864 KB
testcase_32 WA -
testcase_33 AC 59 ms
67,328 KB
testcase_34 AC 85 ms
76,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 18446744073709551615
# inf = 4294967295
md = 10**9+7
# md = 998244353

def gcd(a, b):
    while b: a, b = b, a%b
    return a

def factors(a):
    if a <= 0: return [0]
    dd0, dd1 = [], []
    for d in range(1, round(a**0.5)+1):
        if a%d: continue
        dd0.append(d)
        dd1.append(a//d)
    if dd0[-1] == dd1[-1]: dd1.pop()
    return dd0+dd1[::-1]

n, k = LI()
aa = LI()

if k == 1:
    print((n*(n-1)//2-1)%md)
    exit()

ff = factors(k)
ftoj = {f: j for j, f in enumerate(ff)}
fn = len(ff)

dp = [0]*fn
dp[0] = 1

for a in aa:
    a = gcd(a, k)
    for j in range(fn)[::-1]:
        pre = dp[j]
        if pre == 0: continue
        g = gcd(a*ff[j], k)
        nj = ftoj[g]
        dp[nj] += pre
        dp[nj] %= md
    # print(dp)

print(dp[-1])
0