結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー liny_tailliny_tail
提出日時 2020-09-05 18:53:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 315 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 10,684 KB
実行使用メモリ 29,564 KB
最終ジャッジ日時 2023-08-19 12:43:11
合計ジャッジ時間 5,165 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
29,432 KB
testcase_01 AC 137 ms
29,548 KB
testcase_02 AC 137 ms
29,380 KB
testcase_03 AC 134 ms
29,516 KB
testcase_04 AC 134 ms
29,516 KB
testcase_05 AC 135 ms
29,556 KB
testcase_06 AC 136 ms
29,420 KB
testcase_07 AC 134 ms
29,388 KB
testcase_08 AC 140 ms
29,368 KB
testcase_09 AC 139 ms
29,444 KB
testcase_10 AC 138 ms
29,444 KB
testcase_11 AC 137 ms
29,488 KB
testcase_12 AC 134 ms
29,416 KB
testcase_13 AC 136 ms
29,564 KB
testcase_14 AC 135 ms
29,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

def fib(num1, num2):
  A = np.array([[1,1], [1,0]])
  ans = np.array([[1,0],[0,1]])
  
  for i in bin(num1)[::-1][:-2]:
    if i == '1':
      ans = np.dot(ans, A) % num2
    
    A = np.dot(A,A) % num2
  
  return ans[1][1]

N, M = [int(i) for i in input().strip().split(' ')]
print(fib(N, M))
0