結果
問題 | No.718 行列のできるフィボナッチ数列道場 (1) |
ユーザー |
|
提出日時 | 2018-07-28 01:34:46 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 506 ms / 2,000 ms |
コード長 | 640 bytes |
コンパイル時間 | 183 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 44,464 KB |
最終ジャッジ日時 | 2024-07-05 18:09:01 |
合計ジャッジ時間 | 13,541 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#!/usr/bin/env python3 import numpy as np def powmod(f, n, mod): g = np.identity(4, dtype=np.uint64) for p in map(int, reversed(bin(n)[2 :])): if p: g = g * f % mod f = f * f % mod return g def solve(n): # \begin{pmatrix} F_{i+1}^2 \\ F_{i+1} F_i \\ F_i^2 \\ \sum_{j \le i} F_j^2 \end{pmatrix} x = np.matrix([ 1, 0, 0, 0 ], dtype=np.uint64).transpose() f = np.matrix([ [ 1, 2, 1, 0 ], [ 1, 1, 0, 0 ], [ 1, 0, 0, 0 ], [ 1, 0, 0, 1 ], ], dtype=np.uint64) mod = 10 ** 9 + 7 return (powmod(f, n, mod) * x % mod)[3, 0] print(solve(int(input())))