結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
29,488 KB
testcase_01 AC 113 ms
29,596 KB
testcase_02 AC 115 ms
29,532 KB
testcase_03 AC 114 ms
29,644 KB
testcase_04 AC 115 ms
29,384 KB
testcase_05 AC 115 ms
29,652 KB
testcase_06 AC 126 ms
29,668 KB
testcase_07 AC 126 ms
29,472 KB
testcase_08 AC 124 ms
29,428 KB
testcase_09 AC 116 ms
29,524 KB
testcase_10 AC 116 ms
29,644 KB
testcase_11 AC 118 ms
29,556 KB
testcase_12 AC 119 ms
29,504 KB
testcase_13 AC 124 ms
29,668 KB
testcase_14 AC 118 ms
29,484 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)))
0