結果
| 問題 |
No.1595 The Final Digit
|
| コンテスト | |
| ユーザー |
reatoretch
|
| 提出日時 | 2021-07-09 22:46:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 2,000 ms |
| コード長 | 637 bytes |
| コンパイル時間 | 365 ms |
| コンパイル使用メモリ | 81,792 KB |
| 実行使用メモリ | 60,288 KB |
| 最終ジャッジ日時 | 2024-07-01 17:57:17 |
| 合計ジャッジ時間 | 2,018 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
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])
reatoretch