結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー zundamo-tizundamo-ti
提出日時 2020-10-23 12:46:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 626 ms / 2,000 ms
コード長 640 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 79,036 KB
最終ジャッジ日時 2023-09-28 15:20:52
合計ジャッジ時間 4,664 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,404 KB
testcase_01 AC 70 ms
71,184 KB
testcase_02 AC 70 ms
71,224 KB
testcase_03 AC 74 ms
71,124 KB
testcase_04 AC 73 ms
71,272 KB
testcase_05 AC 72 ms
71,132 KB
testcase_06 AC 72 ms
71,096 KB
testcase_07 AC 81 ms
75,864 KB
testcase_08 AC 96 ms
76,452 KB
testcase_09 AC 110 ms
76,940 KB
testcase_10 AC 346 ms
77,404 KB
testcase_11 AC 626 ms
78,832 KB
testcase_12 AC 564 ms
78,992 KB
testcase_13 AC 613 ms
78,932 KB
testcase_14 AC 531 ms
79,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

def modpow(A, N):
    if N == 0:
        return [[1, 0], [0, 1]]
    if N % 2 == 0:
        return modprd(modpow(A, N // 2), modpow(A, N // 2))
    else:
        return modprd(A, modprd(modpow(A, N // 2), modpow(A, N // 2)))

F = [[0, 1], [1, 1]]
F = modpow(F, N - 1)
print(F[0][1])
0