結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー asumo0729asumo0729
提出日時 2021-04-04 12:20:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 667 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 44,624 KB
最終ジャッジ日時 2024-06-08 04:46:51
合計ジャッジ時間 9,621 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 477 ms
43,980 KB
testcase_01 AC 455 ms
44,372 KB
testcase_02 AC 473 ms
44,360 KB
testcase_03 AC 472 ms
43,856 KB
testcase_04 AC 465 ms
44,240 KB
testcase_05 AC 462 ms
44,364 KB
testcase_06 AC 460 ms
43,852 KB
testcase_07 AC 468 ms
44,236 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 479 ms
44,620 KB
testcase_13 WA -
testcase_14 AC 451 ms
44,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np
stdin=sys.stdin

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
Yp=lambda:print('Yes')
Np=lambda:print('No')

N, M = lp()

A = []
basic = np.array([[0, 1],[1, 1]],dtype=int)
A.append(basic)
for i in range(40):
    now = A[-1]
    nex = np.dot(now,now)
    A.append(nex)
st  = 39
gyouretu = np.eye(2,dtype=int)
N -= 2
while N:
    if 2**st > N:
        st -= 1
        continue
    else:
        N -= 2**st
        gyouretu = np.dot(gyouretu, A[st])
        gyouretu %= M
        st -= 1

ans = np.dot(gyouretu, np.array([0, 1]))
ans %= M

print(ans[1])

0