結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
ユーザー rookzenorookzeno
提出日時 2018-07-27 23:24:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 7,888 KB
最終ジャッジ日時 2023-09-18 14:18:47
合計ジャッジ時間 1,514 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,872 KB
testcase_01 AC 15 ms
7,792 KB
testcase_02 AC 15 ms
7,756 KB
testcase_03 AC 15 ms
7,760 KB
testcase_04 AC 15 ms
7,860 KB
testcase_05 AC 16 ms
7,800 KB
testcase_06 AC 15 ms
7,832 KB
testcase_07 AC 15 ms
7,796 KB
testcase_08 AC 15 ms
7,816 KB
testcase_09 AC 15 ms
7,872 KB
testcase_10 AC 15 ms
7,856 KB
testcase_11 AC 15 ms
7,864 KB
testcase_12 AC 15 ms
7,852 KB
testcase_13 AC 15 ms
7,808 KB
testcase_14 AC 15 ms
7,864 KB
testcase_15 AC 15 ms
7,748 KB
testcase_16 AC 15 ms
7,832 KB
testcase_17 AC 15 ms
7,888 KB
testcase_18 AC 15 ms
7,864 KB
testcase_19 AC 15 ms
7,864 KB
testcase_20 AC 15 ms
7,752 KB
testcase_21 AC 15 ms
7,852 KB
testcase_22 AC 15 ms
7,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
mod = 1000000007
def fib(n):
    if n <= 1:
        return n
    result = [1, 0, 0, 1]
    matrix = [1, 1, 1, 0]
    while n > 0:
        if n % 2:
            result = mul(matrix, result)
        matrix = mul(matrix, matrix)
        n //= 2
    return result[2] % mod

def mul(a, b):
    return [a[0]*b[0]% mod + a[1]*b[2]% mod,
            a[0]*b[1]% mod + a[1]*b[3]% mod,
            a[2]*b[0]% mod + a[3]*b[2]% mod,
            a[2]*b[1]% mod + a[3]*b[3]% mod]
print(fib(N)*fib(N+1)%mod)
0