結果
問題 | No.1595 The Final Digit |
ユーザー |
|
提出日時 | 2021-11-20 01:58:49 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 374 ms / 2,000 ms |
コード長 | 736 bytes |
コンパイル時間 | 434 ms |
コンパイル使用メモリ | 12,288 KB |
実行使用メモリ | 32,312 KB |
最終ジャッジ日時 | 2025-01-02 06:50:04 |
合計ジャッジ時間 | 10,052 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#!/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))