結果
| 問題 |
No.718 行列のできるフィボナッチ数列道場 (1)
|
| コンテスト | |
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2018-07-29 15:11:37 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 493 ms / 2,000 ms |
| コード長 | 610 bytes |
| コンパイル時間 | 178 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 44,612 KB |
| 最終ジャッジ日時 | 2024-07-17 23:41:33 |
| 合計ジャッジ時間 | 13,631 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#!/usr/bin/env python3
import numpy
M = 1000000007
def mod_mul(a, b, mod=M):
return numpy.matmul(a, b) % mod
def mod_pow(a, n, mod=M):
b = numpy.eye(len(a), dtype=a.dtype)
while n > 0:
if n % 2 == 1:
b = mod_mul(a, b, mod)
a = mod_mul(a, a, mod)
n //= 2
return b
def solve(n, mod=M):
a = numpy.array([[1, 1], [1, 0]], dtype=numpy.int64)
v = numpy.array([1, 0], dtype=a.dtype)
res = mod_mul(mod_pow(a, n, mod), v, mod)
return res[0] * res[1] % mod
def main():
print(solve(int(input())))
if __name__ == '__main__':
main()
はむ吉🐹