結果
| 問題 | 
                            No.891 隣接3項間の漸化式
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tktk_snsn
                         | 
                    
| 提出日時 | 2020-12-13 18:29:44 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 637 bytes | 
| コンパイル時間 | 72 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 17,696 KB | 
| 最終ジャッジ日時 | 2024-09-19 23:45:06 | 
| 合計ジャッジ時間 | 4,417 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 10 TLE * 1 -- * 28 | 
ソースコード
def mat_mul(A, B):
    size = len(A)
    res = [[0] * size for _ in range(size)]
    for i in range(size):
        for k in range(size):
            for j in range(size):
                res[i][j] += A[i][k] * B[k][j]
                res[i][j] %= mod
    return res
def mat_pow(A, n):
    size = len(A)
    res = [[0] * size for _ in range(size)]
    for i in range(size):
        res[i][i] = 1
    while n:
        if n & 1:
            res = mat_mul(res, A)
        A = mat_mul(A, A)
        n >>= 1
    return res
mod = 10 ** 9 + 7
a, b, n = map(int, input().split())
A = [[a, b], [1, 0]]
A = mat_pow(A, n-1)
print(A[0][0] % mod)
            
            
            
        
            
tktk_snsn