結果

問題 No.1731 Product of Subsequence
ユーザー mkawa2mkawa2
提出日時 2021-11-05 23:23:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,351 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-24 07:21:50
合計ジャッジ時間 25,272 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 26 ms
10,880 KB
testcase_02 AC 25 ms
10,880 KB
testcase_03 AC 27 ms
10,880 KB
testcase_04 AC 25 ms
10,880 KB
testcase_05 AC 26 ms
10,880 KB
testcase_06 AC 27 ms
11,008 KB
testcase_07 AC 29 ms
10,880 KB
testcase_08 AC 105 ms
11,008 KB
testcase_09 AC 26 ms
11,264 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 AC 34 ms
11,264 KB
testcase_13 AC 81 ms
11,136 KB
testcase_14 AC 1,878 ms
11,136 KB
testcase_15 AC 27 ms
10,880 KB
testcase_16 AC 27 ms
10,880 KB
testcase_17 AC 26 ms
10,880 KB
testcase_18 TLE -
testcase_19 AC 78 ms
11,136 KB
testcase_20 AC 1,730 ms
11,264 KB
testcase_21 TLE -
testcase_22 AC 421 ms
11,136 KB
testcase_23 AC 28 ms
11,264 KB
testcase_24 AC 84 ms
11,136 KB
testcase_25 AC 52 ms
11,136 KB
testcase_26 AC 428 ms
11,136 KB
testcase_27 AC 597 ms
11,136 KB
testcase_28 AC 1,109 ms
11,136 KB
testcase_29 AC 448 ms
11,136 KB
testcase_30 TLE -
testcase_31 AC 389 ms
11,136 KB
testcase_32 AC 28 ms
10,880 KB
testcase_33 AC 57 ms
11,136 KB
testcase_34 AC 188 ms
11,136 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((pow(2, n, md)-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