結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー zundamo-tizundamo-ti
提出日時 2020-10-24 08:03:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 533 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 10,804 KB
実行使用メモリ 7,952 KB
最終ジャッジ日時 2023-09-28 20:09:30
合計ジャッジ時間 1,383 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,948 KB
testcase_01 AC 16 ms
7,952 KB
testcase_02 AC 16 ms
7,812 KB
testcase_03 AC 17 ms
7,888 KB
testcase_04 AC 16 ms
7,816 KB
testcase_05 AC 16 ms
7,760 KB
testcase_06 AC 16 ms
7,888 KB
testcase_07 AC 16 ms
7,868 KB
testcase_08 AC 16 ms
7,848 KB
testcase_09 AC 16 ms
7,756 KB
testcase_10 AC 17 ms
7,800 KB
testcase_11 AC 17 ms
7,860 KB
testcase_12 AC 16 ms
7,844 KB
testcase_13 AC 16 ms
7,900 KB
testcase_14 AC 16 ms
7,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, MOD = map(int, input().split())

def modprd(A_0, A_1):
    a_0, b_0, c_0, d_0 = A_0
    a_1, b_1, c_1, d_1 = A_1
    ret = [0]*4
    ret[0] = (a_0 * a_1 + b_0 * c_1) % MOD
    ret[1] = (a_0 * b_1 + b_0 * d_1) % MOD
    ret[2] = (c_0 * a_1 + d_0 * c_1) % MOD
    ret[3] = (c_0 * b_1 + d_0 * d_1) % MOD
    return ret

def modpow(A, n):
    if n == 0:
        return [1, 0, 0, 1]
    B = modpow(A, n // 2)
    if n & 1:
        return modprd(A, modprd(B, B))
    else:
        return modprd(B, B)

print(modpow([0, 1, 1, 1], N)[0])
0