結果

問題 No.1595 The Final Digit
ユーザー tassei903tassei903
提出日時 2021-07-09 21:45:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 76,400 KB
最終ジャッジ日時 2023-09-14 08:22:50
合計ジャッジ時間 2,865 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,468 KB
testcase_01 AC 73 ms
71,464 KB
testcase_02 AC 76 ms
71,356 KB
testcase_03 AC 78 ms
71,432 KB
testcase_04 AC 80 ms
75,488 KB
testcase_05 AC 80 ms
75,616 KB
testcase_06 AC 81 ms
76,296 KB
testcase_07 AC 81 ms
76,064 KB
testcase_08 AC 73 ms
71,444 KB
testcase_09 AC 73 ms
71,216 KB
testcase_10 AC 73 ms
71,164 KB
testcase_11 AC 74 ms
71,476 KB
testcase_12 AC 73 ms
71,584 KB
testcase_13 AC 75 ms
71,296 KB
testcase_14 AC 79 ms
76,400 KB
testcase_15 AC 79 ms
76,224 KB
testcase_16 AC 79 ms
76,180 KB
testcase_17 AC 73 ms
71,216 KB
testcase_18 AC 72 ms
71,464 KB
testcase_19 AC 78 ms
76,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
sys.setrecursionlimit(10**7)
yes = lambda :print("yes");Yes = lambda :print("Yes")
no = lambda :print("no");No = lambda :print("No")
#######################################################################
p,q,r,K = na()
mod = 10
def mat_mul(a,b):
    n,m,l=len(a),len(b[0]),len(b)
    c=[[0]*m for _ in range(n)]
    for i in range(n):
        for k in range(l):
            for  j in range(m):
                c[i][j]=(c[i][j]+a[i][k]*b[k][j])%mod
    return c
 
#a^nの計算
def mat_pow(a,n):
    m=len(a)
    b=[[0]*m for _ in range(m)]
    for i in range(m):
        b[i][i]=1
    while n>0:
        if n&1:
            b=mat_mul(b,a)
        a=mat_mul(a,a)
        n>>=1
    return b
#print(z)
a = [p%10,q%10,r%10]
if K>=4:
    z = [[1,1,1],[1,0,0],[0,1,0]]
    ans=mat_pow(z,K-3)
    print(sum([ans[0][i]*a[2-i]for i in range(3)])%10)
    #print(ans)
    #print(b)
else:
    print(a[K-1])
0