結果

問題 No.1595 The Final Digit
コンテスト
ユーザー c-yan
提出日時 2021-07-10 00:21:13
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 25 ms / 2,000 ms
+ 1µs
コード長 522 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 66 ms
コンパイル使用メモリ 14,848 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2026-10-13 23:08:41
合計ジャッジ時間 2,123 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

A = {}
A[0] = p % 10
A[1] = q % 10
A[2] = r % 10

def conv(a, b, c):
    return (a % 10) * 100 + (b % 10) * 10 + c % 10

for k in range(3, 2000):
    A[k] = (A[k - 1] + A[k - 2] + A[k - 3]) % 10

if K - 1 < 2000:
    print(A[K - 1])
    exit()

d = {}
for k in range(2, 2000):
    x = conv(A[k], A[k - 1], A[k - 2])
    if x in d:
        loop_start = d[x]
        loop_len = k - loop_start
        break
    d[x] = k

n = ((K - 1) - loop_start) % loop_len + loop_start
print(A[n])
0