結果

問題 No.1731 Product of Subsequence
ユーザー mkawa2mkawa2
提出日時 2021-11-05 23:01:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,397 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 86,528 KB
最終ジャッジ日時 2024-04-24 07:01:22
合計ジャッジ時間 10,938 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 40 ms
52,480 KB
testcase_02 AC 40 ms
52,608 KB
testcase_03 AC 44 ms
57,984 KB
testcase_04 AC 40 ms
52,608 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 47 ms
58,240 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 68 ms
69,248 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 40 ms
52,864 KB
testcase_16 WA -
testcase_17 AC 40 ms
52,608 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 336 ms
77,952 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 337 ms
77,952 KB
testcase_32 WA -
testcase_33 AC 89 ms
76,544 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

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 i, a in enumerate(aa):
    ndp = [0]*fn
    a = gcd(a, k)
    for j in range(fn):
        f = ff[j]
        g = gcd(a*f, k)
        nj = ftoj[g]
        ndp[nj] += dp[j]
        ndp[j] += dp[j]
        dp[nj] %= md
        dp[j] %= md
    dp = ndp
    # print(dp)

print(dp[-1])
0