#P6112. 直接自然溢出啥事没有 加强版

    ID: 6878 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP数学递推O2优化生成函数

直接自然溢出啥事没有 加强版

Background

Original problem link.
The only differences between this problem and the original one are the modulus and the constraints.

Problem Description

Given a positive integer nn, ask how many strings of length nn satisfy that the string is a “program fragment”.

The exact definition is as follows:

A single semicolon ; is a “statement”.

The empty string is a “program fragment”.

If string A is a “program fragment” and string B is a “statement”, then AB is a “program fragment”.

If string A is a “program fragment”, then {A} is a “statement block”.

If string A is a “statement block”, then A is a “statement”, and []A and []()A are both “functions”.

If string A is a “function”, then (A) is a “function”, and A and A() are “values”.

If string A is a “value”, then (A) is a “value”, and A; is a “statement”.

Note: A being B does not mean B is A.

Input Format

Input one line with one positive integer nn.

Output Format

Output one line with one integer representing the answer. As a kind problem setter, you only need to take it modulo 998244353998244353.

4
9
7
140
8923
424180943
114514
552971057

Hint

[Sample 1 Explanation]
Valid “program fragments” include: ;;;;, ;;{}, ;{;}, ;{};, {;;}, {;};, {{}}, {};;, {}{}.

[Constraints]
For 30%30\% of the testdata, 1n1051 \le n \le 10^5.
For 100%100\% of the testdata, 1n1071 \le n \le 10^7.

Translated by ChatGPT 5