結果

問題 No.1595 The Final Digit
ユーザー reatoretchreatoretch
提出日時 2021-07-09 22:46:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 637 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 76,392 KB
最終ジャッジ日時 2023-09-14 10:24:51
合計ジャッジ時間 3,075 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,396 KB
testcase_01 AC 72 ms
71,312 KB
testcase_02 AC 72 ms
71,456 KB
testcase_03 AC 73 ms
71,188 KB
testcase_04 AC 82 ms
75,068 KB
testcase_05 AC 77 ms
75,204 KB
testcase_06 AC 85 ms
75,956 KB
testcase_07 AC 78 ms
76,284 KB
testcase_08 AC 75 ms
71,440 KB
testcase_09 AC 73 ms
71,508 KB
testcase_10 AC 75 ms
71,168 KB
testcase_11 AC 74 ms
71,304 KB
testcase_12 AC 75 ms
71,480 KB
testcase_13 AC 75 ms
71,212 KB
testcase_14 AC 79 ms
76,128 KB
testcase_15 AC 79 ms
76,016 KB
testcase_16 AC 80 ms
76,120 KB
testcase_17 AC 74 ms
71,220 KB
testcase_18 AC 73 ms
71,172 KB
testcase_19 AC 79 ms
76,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

m=10

def mat_mul(a, b) :
    I, J, K = len(a), len(b[0]), len(b)
    c = [[0] * J for _ in range(I)]
    for i in range(I) :
        for j in range(J) :
            for k in range(K) :
                c[i][j] += a[i][k] * b[k][j]
            c[i][j] %= m
    return c

def mat_pow(x, n):
    y = [[0] * len(x) for _ in range(len(x))]
    for i in range(len(x)):
        y[i][i] = 1
    while n > 0:
        if n & 1:
            y = mat_mul(x, y)
        x = mat_mul(x, x)
        n >>= 1
    return y

p,q,r,K=map(int,input().split())
ret = [[r], [q], [p]]
N=K-3
kmat=[[1,1,1],[1,0,0],[0,1,0]]
print(mat_mul(mat_pow(kmat,N),ret)[0][0])
0