結果
| 問題 |
No.526 フィボナッチ数列の第N項をMで割った余りを求める
|
| コンテスト | |
| ユーザー |
kuruton456
|
| 提出日時 | 2020-12-29 13:29:57 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 498 ms / 2,000 ms |
| コード長 | 399 bytes |
| コンパイル時間 | 126 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 44,452 KB |
| 最終ジャッジ日時 | 2024-10-05 11:52:45 |
| 合計ジャッジ時間 | 9,661 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
import numpy as np
N, M = map(int,input().split())
def mat_power(A, M, n):
x = A
ans = np.eye(2, dtype = np.int64)
while(n > 0):
if(bin(n & 1) == bin(1)):
ans = ans.dot(x)
x = x.dot(x)
ans %= M
x %= M
n = n >> 1
return ans
A = np.array([[1,1],[1,0]])
A = mat_power(A, M ,N - 1)
B = np.array([1,0])
C = np.dot(A, B)
print(C[1] % M)
kuruton456