結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
29,556 KB
testcase_01 AC 126 ms
29,492 KB
testcase_02 AC 119 ms
29,636 KB
testcase_03 AC 111 ms
29,524 KB
testcase_04 AC 113 ms
29,472 KB
testcase_05 AC 113 ms
29,560 KB
testcase_06 AC 114 ms
29,560 KB
testcase_07 AC 111 ms
29,624 KB
testcase_08 AC 114 ms
29,540 KB
testcase_09 AC 110 ms
29,596 KB
testcase_10 AC 112 ms
29,636 KB
testcase_11 AC 110 ms
29,508 KB
testcase_12 AC 111 ms
29,552 KB
testcase_13 AC 116 ms
29,556 KB
testcase_14 AC 113 ms
29,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

n,m = map(int,input().split())

def pow_mod(A, k):
    if k==1: return A;

    pm = np.mod(pow_mod(A,k//2), m)
    res = np.mod(np.matmul(pm, pm), m)
    if k%2:
        return np.mod(np.matmul(res, A), m)
    else:
        return res

b = np.array([0, 1])
A = np.array([[0, 1], [1, 1]])

print(np.mod(np.matmul(b,pow_mod(A,n-1)),m)[0])
0