Codeforces Round 1046 (Div. 1)
E2
Beyond the Palindrome (Hard Version)
Codeforces
3500
原题
← E1F →
翻译中…

This is the hard version of the problem. The difference between the versions is that in this version, $n\le 2\cdot 10^7$, and the sum of $n$ over all test cases does not exceed $10^8$. You can hack only if you solved all versions of this problem.

翻译中…

For a binary string$^{\text{∗}}$ $r$, we define $f(r)$ as the result of the following process:

翻译中…
  1. Delete all $\texttt{10}$ substrings$^{\text{†}}$ simultaneously from $r$;
  2. Repeat the above operation until there are no $\texttt{10}$ substrings in $r$.
翻译中…

For example, $f(\mathtt{100110001})=\mathtt{001}$ because $r$ changes as follows: $\mathtt{\underline{10}01\underline{10}001}\to \mathtt{0\underline{10}01}\to\mathtt{001}$.

翻译中…

We call a binary string $s$ almost-palindrome if and only if $f(s)=f(\mathrm{rev}(s))$$^{\text{‡}}$.

翻译中…

Aquawave has given you an integer $n$. You have to help him find the number of distinct almost-palindrome binary strings of length $n$, modulo $998\,244\,353$.

翻译中…

$^{\text{∗}}$A binary string is a string where each character is either $\texttt{0}$ or $\texttt{1}$.$^{\text{†}}$A string $a$ is a substring of a string $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end. $^{\text{‡}}$$\mathrm{rev}(s)$ is the string obtained by writing $s$ from right to left. For example, $\mathrm{rev(\mathtt{10100})=\mathtt{00101}}$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The only line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^7$) — the length of the binary strings.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^8$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the number of distinct almost-palindrome binary strings of length $n$, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test case, all binary strings of length $1$ are almost-palindrome.

翻译中…

In the second test case, all almost-palindrome binary strings of length $2$ are $\mathtt{00}$ and $\mathtt{11}$.

翻译中…

In the third test case, all almost-palindrome binary strings of length $3$ are $\mathtt{000}$, $\mathtt{010}$, $\mathtt{101}$, and $\mathtt{111}$.

翻译中…

样例

Input #1
12
1
2
3
4
5
6
7
8
9
10
100
1024
Output #1
2
2
4
8
12
26
44
86
164
302
307217648
950903700
InputCopy OutputCopy
题目信息
题号
2135E2
时间限制
3 s
内存限制
1024 MB
标签
组合数学
动态规划
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。