結果

問題 No.1595 The Final Digit
ユーザー rin204rin204
提出日時 2021-07-09 21:57:39
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 555 bytes
コンパイル時間 339 ms
使用メモリ 80,812 KB
最終ジャッジ日時 2023-02-01 23:17:39
合計ジャッジ時間 3,672 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 99 ms
76,044 KB
testcase_01 AC 100 ms
76,008 KB
testcase_02 AC 103 ms
76,108 KB
testcase_03 AC 102 ms
75,956 KB
testcase_04 AC 104 ms
76,176 KB
testcase_05 AC 101 ms
76,116 KB
testcase_06 AC 108 ms
80,704 KB
testcase_07 AC 109 ms
80,812 KB
testcase_08 AC 100 ms
76,012 KB
testcase_09 AC 101 ms
76,036 KB
testcase_10 AC 101 ms
76,076 KB
testcase_11 AC 101 ms
75,840 KB
testcase_12 AC 103 ms
76,208 KB
testcase_13 AC 102 ms
75,952 KB
testcase_14 AC 109 ms
80,624 KB
testcase_15 AC 108 ms
80,608 KB
testcase_16 AC 107 ms
80,584 KB
testcase_17 AC 100 ms
75,828 KB
testcase_18 AC 101 ms
76,016 KB
testcase_19 AC 107 ms
80,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy

p, q, r, K = map(int, input().split())

B = [r, q, p]
A = [[1, 1, 1], 
     [1, 0, 0],
     [0, 1, 0]]

K -= 3
while K:
    if K & 1:
        C = [0, 0, 0]
        for i in range(3):
            for j in range(3):
                C[i] += A[i][j] * B[j]
            C[i] %= 10
        B = C.copy()
    C = [[0] * 3 for _ in range(3)]
    for i in range(3):
        for j in range(3):
            for k in range(3):
                C[i][j] += A[i][k] * A[k][j]
            C[i][j] %= 10
    A = deepcopy(C)
    K >>= 1
print(B[0])
0