結果

問題 No.1050 Zero (Maximum)
ユーザー rlangevinrlangevin
提出日時 2023-08-21 12:31:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 77,084 KB
最終ジャッジ日時 2023-08-21 12:31:10
合計ジャッジ時間 3,714 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,508 KB
testcase_01 AC 80 ms
75,968 KB
testcase_02 AC 113 ms
76,472 KB
testcase_03 AC 109 ms
76,952 KB
testcase_04 AC 156 ms
76,672 KB
testcase_05 AC 164 ms
76,552 KB
testcase_06 AC 116 ms
76,488 KB
testcase_07 AC 123 ms
76,644 KB
testcase_08 AC 85 ms
76,388 KB
testcase_09 AC 100 ms
76,180 KB
testcase_10 AC 196 ms
76,804 KB
testcase_11 AC 154 ms
76,884 KB
testcase_12 AC 81 ms
76,512 KB
testcase_13 AC 73 ms
71,420 KB
testcase_14 AC 73 ms
70,972 KB
testcase_15 AC 73 ms
71,536 KB
testcase_16 AC 198 ms
76,732 KB
testcase_17 AC 214 ms
77,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def Matprod(A, B, mod, N):
    temp = [0] * N*N
    for i in range(N):
        for j in range(N):
            ij = i * N + j
            for k in range(N):
                temp[ij] += A[i*N+k] * B[k*N+j]
                temp[ij] %= mod
    return temp

def Matpow_Linear(A, M, mod, N):
    Mat = [0] * N*N
    for i in range(N):
        Mat[i*N+i] = 1
         
    while M:
        if M & 1:
            Mat = Matprod(Mat, A, mod, N)
        A = Matprod(A, A, mod, N)
        M >>= 1
    return Mat  

M, K = map(int, input().split())
A = [0] * (M*M)
for i in range(M):
    for j in range(M):
        nex = (i+j)%M
        A[nex*M+i] += 1
        nex = (i*j)%M
        A[nex*M+i] += 1

mod = 10 ** 9 + 7
A = Matpow_Linear(A, K, mod, M)
print(A[0]%mod)
0