結果
問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める |
ユーザー | asumo0729 |
提出日時 | 2021-04-04 12:54:57 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 140 ms / 2,000 ms |
コード長 | 671 bytes |
コンパイル時間 | 490 ms |
コンパイル使用メモリ | 10,772 KB |
実行使用メモリ | 29,664 KB |
最終ジャッジ日時 | 2023-08-27 12:43:32 |
合計ジャッジ時間 | 5,172 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 133 ms
29,664 KB |
testcase_01 | AC | 136 ms
29,560 KB |
testcase_02 | AC | 135 ms
29,536 KB |
testcase_03 | AC | 132 ms
29,584 KB |
testcase_04 | AC | 132 ms
29,612 KB |
testcase_05 | AC | 132 ms
29,660 KB |
testcase_06 | AC | 136 ms
29,612 KB |
testcase_07 | AC | 139 ms
29,632 KB |
testcase_08 | AC | 140 ms
29,532 KB |
testcase_09 | AC | 133 ms
29,448 KB |
testcase_10 | AC | 130 ms
29,532 KB |
testcase_11 | AC | 131 ms
29,612 KB |
testcase_12 | AC | 128 ms
29,584 KB |
testcase_13 | AC | 130 ms
29,532 KB |
testcase_14 | AC | 131 ms
29,584 KB |
ソースコード
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) nex %= M 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])) print(ans[1])