結果

問題 No.673 カブトムシ
ユーザー norioc
提出日時 2025-02-18 02:13:27
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 383 ms / 2,000 ms
コード長 463 bytes
コンパイル時間 529 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 32,044 KB
最終ジャッジ日時 2025-02-18 02:13:38
合計ジャッジ時間 9,156 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np


def mat_power(m: np.ndarray, n: int, mod: int) -> np.ndarray:
    if n == 0: return np.identity(len(m), dtype=object)
    res = mat_power(m, n // 2, mod)
    res = res @ res % mod
    if n % 2 == 1:
        res = res @ m % mod
    return res


MOD = 10 ** 9 + 7
B, C, D = map(int, input().split())

m = np.array(
    [[C, B],
     [0, 1]])
a = np.array(
    [[B],
     [1]])

t = mat_power(m, D, MOD) @ a
ans = (t[0, 0] - B) % MOD
print(ans)
0