結果

問題 No.1050 Zero (Maximum)
ユーザー H3PO4H3PO4
提出日時 2023-06-30 08:11:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 525 ms / 2,000 ms
コード長 520 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 10,824 KB
実行使用メモリ 32,432 KB
最終ジャッジ日時 2023-09-21 02:34:12
合計ジャッジ時間 7,311 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
29,512 KB
testcase_01 AC 129 ms
29,588 KB
testcase_02 AC 204 ms
30,328 KB
testcase_03 AC 177 ms
30,340 KB
testcase_04 AC 360 ms
31,560 KB
testcase_05 AC 385 ms
31,856 KB
testcase_06 AC 230 ms
30,752 KB
testcase_07 AC 259 ms
30,916 KB
testcase_08 AC 135 ms
29,788 KB
testcase_09 AC 190 ms
30,272 KB
testcase_10 AC 451 ms
32,432 KB
testcase_11 AC 352 ms
31,756 KB
testcase_12 AC 128 ms
29,572 KB
testcase_13 AC 126 ms
29,624 KB
testcase_14 AC 127 ms
29,592 KB
testcase_15 AC 127 ms
29,532 KB
testcase_16 AC 479 ms
32,280 KB
testcase_17 AC 525 ms
32,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

M, K = map(int, input().split())

MOD = 10 ** 9 + 7
A = np.zeros((M, M), dtype=object)
for i in range(M):
    for j in range(M):
        A[i, (i + j) % M] += 1
        A[i, (i * j) % M] += 1


def pow_matrix_mod(x, n, mod=MOD):
    x = x.astype(object)
    if not n:
        return np.eye(len(x), dtype=object)
    if n % 2 == 0:
        return pow_matrix_mod(x @ x % mod, n // 2) % mod
    else:
        return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod


print(pow_matrix_mod(A, K)[0, 0])
0