結果

問題 No.1595 The Final Digit
ユーザー Kiri8128Kiri8128
提出日時 2021-07-09 23:07:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 605 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 76,348 KB
最終ジャッジ日時 2023-09-14 10:39:31
合計ジャッジ時間 2,913 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,552 KB
testcase_01 AC 71 ms
71,608 KB
testcase_02 AC 73 ms
70,992 KB
testcase_03 AC 76 ms
71,448 KB
testcase_04 AC 73 ms
71,292 KB
testcase_05 AC 78 ms
75,696 KB
testcase_06 AC 79 ms
76,224 KB
testcase_07 AC 79 ms
76,136 KB
testcase_08 AC 73 ms
71,404 KB
testcase_09 AC 73 ms
71,456 KB
testcase_10 AC 71 ms
71,312 KB
testcase_11 AC 71 ms
71,404 KB
testcase_12 AC 71 ms
71,024 KB
testcase_13 AC 74 ms
71,288 KB
testcase_14 AC 76 ms
76,144 KB
testcase_15 AC 76 ms
76,348 KB
testcase_16 AC 78 ms
76,184 KB
testcase_17 AC 72 ms
71,188 KB
testcase_18 AC 72 ms
71,200 KB
testcase_19 AC 78 ms
76,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def mmult(A, B):
    global mod
    n, m, l = len(A), len(B), len(B[0])
    ret = [[0] * l for _ in range(n)]
    for i in range(n):
        for j in range(m):
            for k in range(l):
                ret[i][k] = (ret[i][k] + A[i][j] * B[j][k]) % mod
    return ret
def mpow(A, n):
    if n == 1: return A
    if n == 0: return [[1 if i == j else 0 for j in range(len(A))] for i in range(len(A))]
    return mmult(mpow(A, n - 1), A) if n % 2 else mpow(mmult(A, A), n // 2)

mod = 10
p, q, r, K = map(int, input().split())
X = [[0,0,1],[1,0,1],[0,1,1]]
print(mmult([[p, q, r]], mpow(X, K - 1))[0][0])
0