結果

問題 No.891 隣接3項間の漸化式
ユーザー k-kk-k
提出日時 2019-09-21 17:07:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 619 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 113 ms
コンパイル使用メモリ 11,932 KB
実行使用メモリ 76,832 KB
最終ジャッジ日時 2023-10-19 06:27:34
合計ジャッジ時間 25,044 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 619 ms
42,320 KB
testcase_01 AC 487 ms
42,368 KB
testcase_02 AC 483 ms
42,368 KB
testcase_03 AC 488 ms
42,368 KB
testcase_04 AC 486 ms
42,368 KB
testcase_05 AC 483 ms
42,368 KB
testcase_06 AC 484 ms
42,368 KB
testcase_07 AC 484 ms
42,368 KB
testcase_08 AC 482 ms
42,368 KB
testcase_09 AC 483 ms
42,368 KB
testcase_10 AC 486 ms
42,368 KB
testcase_11 AC 480 ms
42,368 KB
testcase_12 AC 487 ms
42,368 KB
testcase_13 AC 488 ms
42,368 KB
testcase_14 AC 482 ms
42,368 KB
testcase_15 AC 484 ms
42,368 KB
testcase_16 AC 482 ms
42,368 KB
testcase_17 AC 487 ms
42,368 KB
testcase_18 AC 491 ms
42,368 KB
testcase_19 AC 493 ms
42,368 KB
testcase_20 AC 492 ms
42,368 KB
testcase_21 AC 490 ms
42,368 KB
testcase_22 AC 487 ms
42,368 KB
testcase_23 AC 487 ms
42,368 KB
testcase_24 AC 485 ms
42,368 KB
testcase_25 AC 492 ms
42,368 KB
testcase_26 AC 494 ms
42,368 KB
testcase_27 AC 494 ms
42,368 KB
testcase_28 AC 484 ms
42,368 KB
testcase_29 AC 488 ms
42,368 KB
testcase_30 AC 484 ms
42,368 KB
testcase_31 AC 489 ms
42,368 KB
testcase_32 AC 481 ms
42,368 KB
testcase_33 AC 497 ms
42,368 KB
testcase_34 AC 499 ms
42,368 KB
testcase_35 AC 489 ms
42,368 KB
testcase_36 AC 486 ms
42,368 KB
testcase_37 AC 489 ms
42,368 KB
testcase_38 AC 483 ms
42,368 KB
testcase_39 AC 481 ms
42,368 KB
testcase_40 AC 482 ms
42,368 KB
testcase_41 AC 496 ms
76,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

MOD = 10 ** 9 + 7
def pow(A, n):
    if n == 0:
        return np.eye(len(A))
    if n == 1:
        return A % MOD
    elif n % 2 == 0:
        return pow(np.dot(A, A) % MOD, n // 2)
    else:
        return np.dot(A, pow(A, n - 1)) % MOD

def calc(a, b, n):
    """
    x_n を計算する
    """
    A = np.array([
        [a, b],
        [1, 0]
    ], dtype="uint64")
    s = np.array([
        [1],
        [0]
    ], dtype="uint64")
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        sq = pow(A, n - 1)
        return np.dot(sq, s)[0][0]

if __name__ == "__main__":
    input_line = input().split(" ")
    print(calc(int(input_line[0]), int(input_line[1]), int(input_line[2])))
0