結果

問題 No.1973 Divisor Sequence
ユーザー hir355hir355
提出日時 2022-06-10 22:14:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,313 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 76,212 KB
最終ジャッジ日時 2023-10-21 06:21:01
合計ジャッジ時間 2,513 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,572 KB
testcase_01 AC 42 ms
55,572 KB
testcase_02 AC 46 ms
61,424 KB
testcase_03 AC 46 ms
59,376 KB
testcase_04 AC 48 ms
61,424 KB
testcase_05 AC 51 ms
59,376 KB
testcase_06 AC 45 ms
55,572 KB
testcase_07 AC 47 ms
61,424 KB
testcase_08 AC 52 ms
61,424 KB
testcase_09 AC 47 ms
61,424 KB
testcase_10 AC 45 ms
55,572 KB
testcase_11 AC 44 ms
55,572 KB
testcase_12 AC 46 ms
61,424 KB
testcase_13 AC 46 ms
61,424 KB
testcase_14 AC 61 ms
68,444 KB
testcase_15 AC 44 ms
55,572 KB
testcase_16 AC 46 ms
61,424 KB
testcase_17 AC 47 ms
61,424 KB
testcase_18 AC 53 ms
64,240 KB
testcase_19 AC 47 ms
61,424 KB
testcase_20 AC 48 ms
61,424 KB
testcase_21 AC 48 ms
61,424 KB
testcase_22 AC 46 ms
61,424 KB
testcase_23 AC 213 ms
76,212 KB
testcase_24 AC 73 ms
72,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        while n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

MOD = 10 ** 9 + 7
n, m = map(int, input().split())
pr = Counter(prime_factorize(m))
res = 1
for x in pr.values():
    mat = [[0] * (x + 1) for _ in range(x + 1)]
    ans = [[0] * (x + 1) for _ in range(x + 1)]
    for i in range(x + 1):
        ans[i][i] = 1
        for j in range(x + 1 - i):
            mat[i][j] = 1
    tk = n + 1
    while tk > 0:
        if tk & 1:
            t = [[0] * (x + 1) for _ in range(x + 1)]
            for i in range(x + 1):
                for j in range(x + 1):
                    for k in range(x + 1):
                        t[i][j] += mat[i][k] * ans[k][j] % MOD
            for i in range(x + 1):
                ans[i] = t[i][:]
        t = [[0] * (x + 1) for _ in range(x + 1)]
        for i in range(x + 1):
            for j in range(x + 1):
                for k in range(x + 1):
                    t[i][j] += mat[i][k] * mat[k][j] % MOD
        for i in range(x + 1):
            mat[i] = t[i][:]
        tk >>= 1
    res *= ans[0][0]
print(res % MOD)
0