結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー ajinoriajinori
提出日時 2018-11-22 20:15:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,612 ms / 2,000 ms
コード長 429 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 10,740 KB
実行使用メモリ 29,576 KB
最終ジャッジ日時 2023-08-26 03:58:59
合計ジャッジ時間 8,703 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
29,472 KB
testcase_01 AC 129 ms
29,440 KB
testcase_02 AC 129 ms
29,412 KB
testcase_03 AC 129 ms
29,492 KB
testcase_04 AC 133 ms
29,544 KB
testcase_05 AC 132 ms
29,576 KB
testcase_06 AC 136 ms
29,452 KB
testcase_07 AC 130 ms
29,448 KB
testcase_08 AC 139 ms
29,436 KB
testcase_09 AC 157 ms
29,520 KB
testcase_10 AC 351 ms
29,564 KB
testcase_11 AC 1,558 ms
29,472 KB
testcase_12 AC 1,206 ms
29,476 KB
testcase_13 AC 1,612 ms
29,464 KB
testcase_14 AC 1,416 ms
29,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import functools
import numpy as np
n,m= map(int,input().split())
# @functools.lru_cache(maxsize = None)
#
# def func(p):
#     if p==1 : return np.mod(arr,m)
#     if p%2==1:
#         return np.mod(func(p-1)*arr,m)
#     else:
#         return np.mod(func(p//2)*func(p//2),m)
#
# arr = np.mat([[0,1],[1,1]])
# bb = np.mat([0,1])*func(n-1)
# print(bb.item((0,0)))
a = 0
b = 1
for i in range(n-2):
    a,b = (b,(a+b)%m)
print(b)
0