結果

問題 No.1050 Zero (Maximum)
ユーザー H3PO4
提出日時 2020-05-08 22:49:21
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 512 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 44,596 KB
最終ジャッジ日時 2024-07-04 01:04:28
合計ジャッジ時間 11,424 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 4 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

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

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


def pow_matrix_mod(x, n):
    if n == 0:
        return np.eye(M, dtype=np.int64)
    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