結果

問題 No.1595 The Final Digit
ユーザー stng
提出日時 2021-07-18 13:34:00
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 640 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 26,432 KB
最終ジャッジ日時 2024-07-08 07:03:14
合計ジャッジ時間 1,841 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def srh(A,B,C):
    a[0],a[1],a[2] = A,B,C
    for i in range(3,len(a)):
        a[i] = a[i-1] + a[i-2] + a[i-3]
        a[i] %= 10
        if a[i-2] == a[0] and a[i-1] == a[1] and a[i] == a[2]:
            return i-2,a[:i-2]
            
"""
for i in range(3,len(a)):
    a[i] = a[i-1] + a[i-2] + a[i-3]
    a[i] %= 10
    if a[i-2] == a[0] and a[i-1] == a[1] and a[i] == a[2]:
        idx = i
        break
"""

K -= 4

a = [0]*10**6
f_idx , fst = srh(1,1,2)
a = [0]*10**6
s_idx , snd = srh(1,2,3)
a = [0]*10**6
t_idx , trd = srh(1,2,4)

ans = fst[K%f_idx]*p+snd[K%s_idx]*q+trd[K%t_idx]*r
print(ans%10)
0