結果
問題 |
No.720 行列のできるフィボナッチ数列道場 (2)
|
ユーザー |
|
提出日時 | 2018-07-28 01:38:53 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 507 ms / 2,000 ms |
コード長 | 740 bytes |
コンパイル時間 | 129 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 44,472 KB |
最終ジャッジ日時 | 2024-07-05 18:09:49 |
合計ジャッジ時間 | 12,863 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#!/usr/bin/env python3 import numpy as np def powmod(f, n, mod): g = np.identity(3, 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, m): # \begin{pmatrix} F_{2i+1} \\ F_{2i} \\ \sum_{j \le i} F_{2j} \end{pmatrix} x = np.matrix([ 1, 0, 0 ], dtype=np.uint64).transpose() f = np.matrix([ [ 1, 1, 0 ], [ 1, 0, 0 ], [ 0, 0, 1 ], ], dtype=np.uint64) g = np.matrix([ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 1, 1 ], ], dtype=np.uint64) mod = 10 ** 9 + 7 return (powmod(g * powmod(f, m, mod) % mod, n, mod) * x % mod)[2, 0] print(solve(*map(int, input().split())))