結果

問題 No.2156 ぞい文字列
ユーザー tomoyawatomoyawa
提出日時 2023-01-02 20:22:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 424 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 29,632 KB
最終ジャッジ日時 2023-08-17 23:48:52
合計ジャッジ時間 6,481 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
29,512 KB
testcase_01 AC 135 ms
29,624 KB
testcase_02 AC 134 ms
29,576 KB
testcase_03 AC 134 ms
29,632 KB
testcase_04 AC 136 ms
29,632 KB
testcase_05 AC 140 ms
29,560 KB
testcase_06 AC 140 ms
29,500 KB
testcase_07 AC 142 ms
29,576 KB
testcase_08 AC 134 ms
29,572 KB
testcase_09 AC 136 ms
29,572 KB
testcase_10 AC 133 ms
29,412 KB
testcase_11 AC 133 ms
29,408 KB
testcase_12 AC 129 ms
29,408 KB
testcase_13 AC 127 ms
29,564 KB
testcase_14 AC 127 ms
29,412 KB
testcase_15 AC 129 ms
29,612 KB
testcase_16 AC 128 ms
29,536 KB
testcase_17 AC 127 ms
29,600 KB
testcase_18 AC 128 ms
29,616 KB
testcase_19 AC 137 ms
29,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
import math
M = 998244353
def fibmtx2n(k):   # n = 2 ** n2
  fm = np.array([[1,1],[1,0]], dtype='object')
  for i in range(k): 
    fm = np.dot(fm,fm) % M
  return fm
def fibmtx(n):
  fm1 = np.array([[1,0],[0,1]],dtype='object')
  while n > 0:
    l2n = n.bit_length()-1
    fm1 = np.dot(fm1, fibmtx2n(l2n)) % M
    n -= 2**l2n
  return fm1[0][1]

N=int(input())
ans=(fibmtx(N)+fibmtx(N-1)-1)%M
print(ans)
0