結果
| 問題 | No.718 行列のできるフィボナッチ数列道場 (1) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-07-27 23:30:58 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 626 bytes |
| 記録 | |
| コンパイル時間 | 141 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 25,628 KB |
| 最終ジャッジ日時 | 2024-07-05 05:26:09 |
| 合計ジャッジ時間 | 6,577 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 19 |
ソースコード
from sys import stdin, stdout
input = lambda: stdin.readline().rstrip()
write = stdout.write
def main():
N = int(input())
mod = 1000000007
ans = (fib(N) % mod) * (fib(N + 1) % mod) % mod
print(ans)
def fib(n):
if n < 2:
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] + a[1]*b[2],
a[0]*b[1] + a[1]*b[3],
a[2]*b[0] + a[3]*b[2],
a[2]*b[1] + a[3]*b[3]]
main()