結果
問題 | No.2156 ぞい文字列 |
ユーザー | terasa |
提出日時 | 2022-12-09 22:06:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 73 ms / 2,000 ms |
コード長 | 1,473 bytes |
コンパイル時間 | 366 ms |
コンパイル使用メモリ | 82,336 KB |
実行使用メモリ | 68,608 KB |
最終ジャッジ日時 | 2024-10-14 22:03:56 |
合計ジャッジ時間 | 2,594 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
from typing import List, Tuple, Callable, TypeVar, Optional import sys import itertools import heapq import bisect import math from collections import deque, defaultdict from functools import lru_cache, cmp_to_key input = sys.stdin.readline if __file__ != 'prog.py': sys.setrecursionlimit(10 ** 6) def readints(): return map(int, input().split()) def readlist(): return list(readints()) def readstr(): return input()[:-1] class Matpow: def __init__(self, A, mod, digit=60): self.A = A self.N = len(A) self.mod = mod self.digit = digit self.doubling = [None] * self.digit self.doubling[0] = A for i in range(1, self.digit): self.doubling[i] = self.mul(self.doubling[i - 1], self.doubling[i - 1]) def pow(self, n): E = [[1 if i == j else 0 for j in range(self.N)] for i in range(self.N)] acc = E for k in range(self.digit): if n & (1 << k): acc = self.mul(acc, self.doubling[k]) return acc def mul(self, A, B): C = [[0 for _ in range(self.N)] for _ in range(self.N)] for i in range(self.N): for j in range(self.N): for k in range(self.N): C[i][j] += A[i][k] * B[k][j] C[i][j] %= self.mod return C N = int(input()) mod = 998244353 A = [[1, 1], [1, 0]] An = Matpow(A, mod).pow(N - 1) ans = (sum(An[0]) - 1) % mod print(ans)