結果

問題 No.891 隣接3項間の漸化式
ユーザー H3PO4H3PO4
提出日時 2021-03-08 09:49:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 580 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 44,356 KB
最終ジャッジ日時 2024-04-18 01:21:07
合計ジャッジ時間 24,557 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 521 ms
43,836 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 507 ms
43,704 KB
testcase_14 AC 516 ms
44,096 KB
testcase_15 AC 512 ms
44,092 KB
testcase_16 AC 510 ms
44,220 KB
testcase_17 AC 511 ms
43,976 KB
testcase_18 AC 500 ms
44,348 KB
testcase_19 AC 512 ms
43,836 KB
testcase_20 AC 508 ms
44,348 KB
testcase_21 AC 516 ms
44,100 KB
testcase_22 AC 508 ms
43,708 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

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


def pow_matrix_mod(x, n, mod=MOD):
    if not n:
        return np.eye(len(x), dtype=np.object)
    if n % 2 == 0:
        return pow_matrix_mod(x @ x % mod, n // 2) % mod
    else:
        return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod


if A == 0 and B == 0:
    ans = 1 if N == 1 else 0
elif A == 0:
    ans = pow(B, N // 2, MOD) if N % 2 else 0
elif B == 0:
    ans = pow(A, N - 1, MOD) if N else 0
else:
    X = np.array([[0, 1], [B, A]])
    ans = pow_matrix_mod(X, N)[0, 1]
print(ans)
0