結果

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

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 84 ms
75,828 KB
testcase_01 AC 84 ms
75,776 KB
testcase_02 AC 84 ms
75,576 KB
testcase_03 AC 84 ms
75,804 KB
testcase_04 AC 87 ms
80,320 KB
testcase_05 AC 87 ms
80,324 KB
testcase_06 AC 90 ms
80,728 KB
testcase_07 AC 89 ms
80,860 KB
testcase_08 AC 81 ms
75,792 KB
testcase_09 AC 82 ms
75,508 KB
testcase_10 AC 84 ms
75,840 KB
testcase_11 AC 82 ms
75,792 KB
testcase_12 AC 82 ms
75,832 KB
testcase_13 AC 88 ms
75,748 KB
testcase_14 AC 92 ms
80,692 KB
testcase_15 AC 91 ms
80,508 KB
testcase_16 AC 90 ms
80,776 KB
testcase_17 AC 84 ms
75,668 KB
testcase_18 AC 85 ms
75,788 KB
testcase_19 AC 91 ms
80,676 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