結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
ユーザー Rustの読みはラストRustの読みはラスト
提出日時 2018-07-27 23:28:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 574 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 71,300 KB
最終ジャッジ日時 2023-09-18 14:31:14
合計ジャッジ時間 3,172 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,288 KB
testcase_01 AC 74 ms
71,208 KB
testcase_02 AC 76 ms
71,300 KB
testcase_03 AC 77 ms
70,920 KB
testcase_04 AC 76 ms
70,964 KB
testcase_05 AC 74 ms
71,216 KB
testcase_06 AC 76 ms
71,084 KB
testcase_07 AC 76 ms
71,120 KB
testcase_08 AC 77 ms
71,140 KB
testcase_09 AC 74 ms
70,924 KB
testcase_10 AC 74 ms
70,924 KB
testcase_11 AC 73 ms
71,080 KB
testcase_12 AC 76 ms
71,228 KB
testcase_13 AC 76 ms
71,284 KB
testcase_14 AC 74 ms
71,240 KB
testcase_15 AC 77 ms
71,124 KB
testcase_16 AC 77 ms
71,236 KB
testcase_17 AC 77 ms
71,208 KB
testcase_18 AC 79 ms
71,136 KB
testcase_19 AC 76 ms
71,236 KB
testcase_20 AC 77 ms
70,956 KB
testcase_21 AC 75 ms
71,180 KB
testcase_22 AC 75 ms
71,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

M = 1000000007

# qiita.com/SaitoTsutomu/items/be069ea89c85191799fa
def fib2(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]

def mul(a, b):
    return [a[0]*b[0] % M + a[1]*b[2] % M,
            a[0]*b[1] % M + a[1]*b[3] % M,
            a[2]*b[0] % M + a[3]*b[2] % M,
            a[2]*b[1] % M + a[3]*b[3] % M]
            
n = int(input())
ans = fib2(n) * fib2(n+1) % M
print(ans)
0