結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー kazu_eykazu_ey
提出日時 2021-01-12 22:30:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 459 ms / 2,000 ms
コード長 382 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 44,448 KB
最終ジャッジ日時 2024-05-01 08:56:05
合計ジャッジ時間 9,651 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 453 ms
43,932 KB
testcase_01 AC 448 ms
43,932 KB
testcase_02 AC 451 ms
44,056 KB
testcase_03 AC 449 ms
44,312 KB
testcase_04 AC 448 ms
44,312 KB
testcase_05 AC 456 ms
44,316 KB
testcase_06 AC 444 ms
44,440 KB
testcase_07 AC 443 ms
43,932 KB
testcase_08 AC 438 ms
44,052 KB
testcase_09 AC 452 ms
44,188 KB
testcase_10 AC 438 ms
43,924 KB
testcase_11 AC 442 ms
44,188 KB
testcase_12 AC 446 ms
44,316 KB
testcase_13 AC 451 ms
44,108 KB
testcase_14 AC 459 ms
44,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def mat_pow(arr,num,mod):  # 行列arr**num
    import numpy as np
    mat=np.array(arr,dtype="O")%mod
    res=np.eye(len(arr),dtype="O")
    while num:
        if num&1:
            res=res@mat%mod
        mat=mat@mat%mod
        num>>=1
    return res


import sys
input=sys.stdin.readline
n,m=map(int,input().split())
a=[[1,1],[1,0]]
res=mat_pow(a,n-2,m)@[[1],[0]]
print(*res[0])
0