結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー kazu_ey
提出日時 2021-01-12 22:30:27
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 561 ms / 2,000 ms
コード長 382 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 44,316 KB
最終ジャッジ日時 2024-11-21 12:07:44
合計ジャッジ時間 11,329 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

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