結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー kuruton456kuruton456
提出日時 2020-12-29 13:29:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 553 ms / 2,000 ms
コード長 399 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 44,440 KB
最終ジャッジ日時 2024-04-15 14:23:50
合計ジャッジ時間 10,359 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 553 ms
44,200 KB
testcase_01 AC 545 ms
44,192 KB
testcase_02 AC 538 ms
43,940 KB
testcase_03 AC 545 ms
44,072 KB
testcase_04 AC 533 ms
44,064 KB
testcase_05 AC 537 ms
44,200 KB
testcase_06 AC 539 ms
43,976 KB
testcase_07 AC 535 ms
44,060 KB
testcase_08 AC 551 ms
43,936 KB
testcase_09 AC 540 ms
44,068 KB
testcase_10 AC 542 ms
43,940 KB
testcase_11 AC 545 ms
43,944 KB
testcase_12 AC 546 ms
43,932 KB
testcase_13 AC 547 ms
44,440 KB
testcase_14 AC 542 ms
44,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
N, M = map(int,input().split())

def mat_power(A, M, n):
    x = A
    ans = np.eye(2, dtype = np.int64)
    while(n > 0):
        if(bin(n & 1) == bin(1)):
            ans = ans.dot(x)
        x = x.dot(x)
        ans %= M
        x %= M
        n = n >> 1
    return ans
A = np.array([[1,1],[1,0]])
A = mat_power(A, M ,N - 1)
B = np.array([1,0])
C = np.dot(A, B)
print(C[1] % M)
0