結果

問題 No.1595 The Final Digit
ユーザー wolgnikwolgnik
提出日時 2021-07-09 21:52:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 86,816 KB
実行使用メモリ 76,520 KB
最終ジャッジ日時 2023-09-14 08:45:47
合計ジャッジ時間 3,023 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,368 KB
testcase_01 AC 77 ms
71,492 KB
testcase_02 AC 73 ms
71,404 KB
testcase_03 AC 74 ms
71,424 KB
testcase_04 AC 78 ms
75,560 KB
testcase_05 AC 78 ms
76,080 KB
testcase_06 AC 79 ms
76,456 KB
testcase_07 AC 78 ms
76,120 KB
testcase_08 AC 72 ms
71,216 KB
testcase_09 AC 74 ms
71,228 KB
testcase_10 AC 74 ms
71,164 KB
testcase_11 AC 72 ms
71,212 KB
testcase_12 AC 72 ms
71,568 KB
testcase_13 AC 74 ms
71,224 KB
testcase_14 AC 79 ms
76,488 KB
testcase_15 AC 79 ms
76,496 KB
testcase_16 AC 77 ms
76,520 KB
testcase_17 AC 72 ms
71,420 KB
testcase_18 AC 74 ms
71,388 KB
testcase_19 AC 80 ms
76,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
p, q, r, K = map(int, input().split())

def ArrayMultiple(a, b, mod):
  n = len(a)
  m = len(b[0])
  c = [[0] * n for _ in range(n)]
  for i in range(n):
    for j in range(m):
      for k in range(n):
        c[i][j] += a[i][k] * b[k][j]
        c[i][j] %= mod
  return c

def ArrayPower(a, k, mod):
  bn = list(bin(k)[2: ])
  ln = len(bn)
  n = len(a)
  bn.reverse()
  res = [[int(i == x) for i in range(n)] for x in range(n)]
  for i in range(ln):
    if int(bn[i]):
      res = ArrayMultiple(res, a, mod)
    a = ArrayMultiple(a, a, mod)
  return res

a = [[1, 1, 1], [1, 0, 0], [0, 1, 0]]
ak = ArrayPower(a, K - 3, 10)[0]
print((ak[0] * r + ak[1] * q + ak[2] * p) % 10)
0