結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-21 22:50:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 81,620 KB
実行使用メモリ 53,512 KB
最終ジャッジ日時 2023-10-21 11:55:26
合計ジャッジ時間 2,383 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,512 KB
testcase_01 AC 40 ms
53,512 KB
testcase_02 AC 41 ms
53,512 KB
testcase_03 AC 41 ms
53,512 KB
testcase_04 AC 42 ms
53,512 KB
testcase_05 AC 41 ms
53,512 KB
testcase_06 AC 41 ms
53,512 KB
testcase_07 AC 41 ms
53,512 KB
testcase_08 AC 41 ms
53,512 KB
testcase_09 AC 41 ms
53,512 KB
testcase_10 AC 40 ms
53,512 KB
testcase_11 AC 41 ms
53,512 KB
testcase_12 AC 40 ms
53,512 KB
testcase_13 AC 41 ms
53,512 KB
testcase_14 AC 40 ms
53,512 KB
testcase_15 AC 41 ms
53,512 KB
testcase_16 AC 40 ms
53,512 KB
testcase_17 AC 40 ms
53,512 KB
testcase_18 AC 40 ms
53,512 KB
testcase_19 AC 40 ms
53,512 KB
testcase_20 AC 40 ms
53,512 KB
testcase_21 AC 40 ms
53,512 KB
testcase_22 AC 40 ms
53,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7


def mat_mul(A, B):
    res = [[0] * len(B[0]) for _ in range(len(A))]
    for i in range(len(A)):
        for k in range(len(A[0])):
            for j in range(len(B[0])):
                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


N = int(input())
A = [[1, 1], [1, 0]]
A = mat_pow(A, N)

x = A[0][0]
y = A[1][0]
print(x * y % mod)
0