結果

問題 No.1595 The Final Digit
ユーザー norioc
提出日時 2025-05-27 10:14:43
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 510 bytes
コンパイル時間 459 ms
コンパイル使用メモリ 82,596 KB
実行使用メモリ 67,520 KB
最終ジャッジ日時 2025-05-27 10:14:46
合計ジャッジ時間 3,144 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np


def mat_power(m: np.ndarray, n: int, mod: int) -> np.ndarray:
    if n == 0: return np.identity(len(m), dtype=object)
    res = mat_power(m, n // 2, mod)
    res = res @ res % mod
    if n % 2 == 1:
        res = res @ m % mod
    return res


MOD = 10
P, Q, R, K = map(int, input().split())
P %= 10
Q %= 10
R %= 10

m = np.array(
    [[1, 1, 1],
     [1, 0, 0],
     [0, 1, 0]])

a = np.array(
    [[R],
     [Q],
     [P]])

t = mat_power(m, K-3, MOD) @ a
ans = t[0, 0] % MOD
print(ans)
0