結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
コンテスト
ユーザー rookzeno
提出日時 2018-07-27 23:24:45
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 508 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 391 ms
コンパイル使用メモリ 20,956 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2026-03-26 12:02:56
合計ジャッジ時間 3,691 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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