Codeforces Round 819 (Div. 1 + Div. 2) and Grimoire of Code Annual Contest 2022
E
Almost Perfect
Codeforces
2400
原题
← DF →
翻译中…

A permutation $p$ of length $n$ is called almost perfect if for all integer $1 \leq i \leq n$, it holds that $\lvert p_i - p^{-1}_i \rvert \le 1$, where $p^{-1}$ is the inverse permutation of $p$ (i.e. $p^{-1}_{k_1} = k_2$ if and only if $p_{k_2} = k_1$).

翻译中…

Count the number of almost perfect permutations of length $n$ modulo $998244353$.

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1 \leq t \leq 1000$) — the number of test cases. The description of each test case follows.

翻译中…

The first and only line of each test case contains a single integer $n$ ($1 \leq n \leq 3 \cdot 10^5$) — the length of the permutation.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the number of almost perfect permutations of length $n$ modulo $998244353$.

翻译中…

Note

翻译中…

For $n = 2$, both permutations $[1, 2]$, and $[2, 1]$ are almost perfect.

翻译中…

For $n = 3$, there are only $6$ permutations. Having a look at all of them gives us:

翻译中…
  • $[1, 2, 3]$ is an almost perfect permutation.
  • $[1, 3, 2]$ is an almost perfect permutation.
  • $[2, 1, 3]$ is an almost perfect permutation.
  • $[2, 3, 1]$ is NOT an almost perfect permutation ($\lvert p_2 - p^{-1}_2 \rvert = \lvert 3 - 1 \rvert = 2$).
  • $[3, 1, 2]$ is NOT an almost perfect permutation ($\lvert p_2 - p^{-1}_2 \rvert = \lvert 1 - 3 \rvert = 2$).
  • $[3, 2, 1]$ is an almost perfect permutation.
翻译中…

So we get $4$ almost perfect permutations.

翻译中…

样例

Input #1
3
2
3
50
Output #1
2
4
830690567
InputCopy OutputCopy
题目信息
题号
1726E
时间限制
3 s
内存限制
256 MB
标签
组合数学
FFT
数学

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