結果

問題 No.1595 The Final Digit
ユーザー tcltktcltk
提出日時 2021-11-20 01:58:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 736 bytes
コンパイル時間 1,645 ms
コンパイル使用メモリ 10,748 KB
実行使用メモリ 62,148 KB
最終ジャッジ日時 2023-08-30 15:22:04
合計ジャッジ時間 8,287 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
29,872 KB
testcase_01 AC 134 ms
29,936 KB
testcase_02 AC 133 ms
29,892 KB
testcase_03 AC 134 ms
29,904 KB
testcase_04 AC 135 ms
29,892 KB
testcase_05 AC 133 ms
29,972 KB
testcase_06 AC 133 ms
29,980 KB
testcase_07 AC 134 ms
29,860 KB
testcase_08 AC 131 ms
29,828 KB
testcase_09 AC 134 ms
29,908 KB
testcase_10 AC 132 ms
29,960 KB
testcase_11 AC 135 ms
29,940 KB
testcase_12 AC 132 ms
29,852 KB
testcase_13 AC 132 ms
29,952 KB
testcase_14 AC 137 ms
29,956 KB
testcase_15 AC 134 ms
29,992 KB
testcase_16 AC 134 ms
30,000 KB
testcase_17 AC 140 ms
29,944 KB
testcase_18 AC 133 ms
30,068 KB
testcase_19 AC 134 ms
62,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import numpy as np
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """86 91 20 1001
# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10


def solve(p, q, r, K):

    N = K-3
    A = np.matrix([[1, 1, 1], [1, 0, 0], [0, 1, 0]])
    M = A
    An = np.identity(M.shape[0], dtype=object)
    while N:
        if N & 1:
            An = np.mod(An * M, 10)
        M = np.mod(M * M, 10)
        N >>= 1
    v = An * np.array([[r], [q], [p]])
    return v[0, 0] % 10

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