結果
| 問題 |
No.718 行列のできるフィボナッチ数列道場 (1)
|
| コンテスト | |
| ユーザー |
simamumu
|
| 提出日時 | 2018-07-28 00:10:40 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 2,000 ms |
| コード長 | 703 bytes |
| コンパイル時間 | 132 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-07-05 17:08:39 |
| 合計ジャッジ時間 | 1,575 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]
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] + a[1]*b[2])%mod,
(a[0]*b[1] + a[1]*b[3])%mod,
(a[2]*b[0] + a[3]*b[2])%mod,
(a[2]*b[1] + a[3]*b[3])%mod]
N = int(input())
print(fib(N)*fib(N+1)%mod)
simamumu