結果

問題 No.891 隣接3項間の漸化式
ユーザー あかしあみどりあかしあみどり
提出日時 2023-02-17 21:28:50
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,194 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 86,764 KB
実行使用メモリ 82,956 KB
最終ジャッジ日時 2023-09-26 18:35:14
合計ジャッジ時間 6,173 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
78,108 KB
testcase_01 AC 73 ms
71,136 KB
testcase_02 AC 73 ms
71,176 KB
testcase_03 AC 78 ms
71,176 KB
testcase_04 AC 74 ms
71,288 KB
testcase_05 AC 75 ms
71,224 KB
testcase_06 AC 74 ms
71,344 KB
testcase_07 AC 73 ms
71,484 KB
testcase_08 AC 74 ms
71,236 KB
testcase_09 AC 75 ms
71,204 KB
testcase_10 AC 74 ms
71,004 KB
testcase_11 AC 74 ms
71,012 KB
testcase_12 AC 75 ms
71,312 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def oi(): return int(input())
def os(): return input()
def mi(): return list(map(int, input().split()))

# import sys
# input = sys.stdin.readline
# import sys
# sys.setrecursionlimit(10**8)
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
input_count = 0

input_count = 0
a,b,n = mi()
mod = 10**9+7
def prod_func(a,b):
    # 累乗部分がデカすぎてメモリが死んじゃう時など
    # 例えば10^18回移動して到達できる場所はどこ?というときはこれで良い
    return (a*b)%mod
def add_func(a,b):
    return a+b

class MATRIX:
    def __init__(self, prod_func, add_func):
        self.prod_func = prod_func
        self.add_func = add_func
        
    def dot(self, A,B):
        if len(A[0]) != len(B):
            return None
        out = [[0] * len(B[0]) for _ in range(len(A))]
        for ay in range(len(A)):
            for bx in range(len(B[0])):
                sums = 0
                for ax in range(len(A[0])):
                    sums += self.prod_func(A[ay][ax], B[ax][bx])
                out[ay][bx] = sums
        return out

    def sum(self, A,B):
        if not(len(A) == len(B) and len(A[0]) == len(B[0])):
            return None
        out = []
        for ay in range(len(A)):
            temp = []
            for ax in range(len(A[0])):
                temp.append(self.add_func(A[ay][ax], B[ay][ax]))
            out.append(temp)
        return out

    def prod(self, A,B):
        if not(len(A) == len(B) and len(A[0]) == len(B[0])):
            return None
        out = []
        for ay in range(len(A)):
            temp = []
            for ax in range(len(A[0])):
                temp.append(self.prod_func(A[ay][ax], B[ay][ax]))
            out.append(temp)
        return out

    # 正方行列AをN乗する。
    def ruijou(self, A, N):
        out = [[0] * len(A) for _ in range(len(A))]
        for i in range(len(A)):
            out[i][i] = 1

        while N:
            if N%2==1:
                out = self.dot(out, A)
            A = self.dot(A,A)
            N//=2
        return out

MAT = MATRIX(prod_func=prod_func, add_func=add_func)
print(MAT.ruijou([[a, b],[1,0]], n-1)[0][0]%mod)
0