CF1726E.Almost Perfect

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A permutation pp of length nn is called almost perfect if for all integer 1≤i≤n1 \leq i \leq n, it holds that ∣pi−pi−1∣≤1\lvert p_i - p^{-1}_i \rvert \le 1, where p−1p^{-1} is the inverse permutation of pp (i.e. pk1−1=k2p^{-1}_{k_1} = k_2 if and only if pk2=k1p_{k_2} = k_1).

Count the number of almost perfect permutations of length nn modulo 998244353998244353.

长度为 nn 的排列 pp 被称为几乎完美排列,当且仅当对所有整数 1≤i≤n1 \leq i \leq n,均满足 ∣pi−pi−1∣≤1\lvert p_i - p^{-1}_i \rvert \le 1,其中 p−1p^{-1} 是 pp 的逆排列(即:pk1−1=k2p^{-1}_{k_1} = k_2 当且仅当 pk2=k1p_{k_2} = k_1)。

求长度为 nn 的几乎完美排列的个数,对 998244353998244353 取模。

输入格式

The first line contains a single integer tt (1≤t≤10001 \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 nn (1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5) — the length of the permutation.

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

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是每个测试用例的描述。

每个测试用例仅有一行,包含一个整数 nn(1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5),表示排列的长度。

保证所有测试用例的 nn 值之和不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, output a single integer — the number of almost perfect permutations of length nn modulo 998244353998244353.

对于每个测试用例,输出一个整数——长度为 nn 的几乎完美排列的个数对 998244353998244353 取模的结果。

输入输出样例

  • 输入#1

    3
    2
    3
    50

    输出#1

    2
    4
    830690567

说明/提示

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

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

  • [1,2,3][1, 2, 3] is an almost perfect permutation.
  • [1,3,2][1, 3, 2] is an almost perfect permutation.
  • [2,1,3][2, 1, 3] is an almost perfect permutation.
  • [2,3,1][2, 3, 1] is NOT an almost perfect permutation (∣p2−p2−1∣=∣3−1∣=2\lvert p_2 - p^{-1}_2 \rvert = \lvert 3 - 1 \rvert = 2).
  • [3,1,2][3, 1, 2] is NOT an almost perfect permutation (∣p2−p2−1∣=∣1−3∣=2\lvert p_2 - p^{-1}_2 \rvert = \lvert 1 - 3 \rvert = 2).
  • [3,2,1][3, 2, 1] is an almost perfect permutation.

So we get 44 almost perfect permutations.

当 n=2n = 2 时,排列 [1,2][1, 2] 和 [2,1][2, 1] 均为几乎完美排列。

当 n=3n = 3 时,共有 66 个排列。逐一检验所有排列可得:

  • [1,2,3][1, 2, 3] 是一个几乎完美排列。
  • [1,3,2][1, 3, 2] 是一个几乎完美排列。
  • [2,1,3][2, 1, 3] 是一个几乎完美排列。
  • [2,3,1][2, 3, 1] 不是一个几乎完美排列(∣p2−p2−1∣=∣3−1∣=2\lvert p_2 - p^{-1}_2 \rvert = \lvert 3 - 1 \rvert = 2)。
  • [3,1,2][3, 1, 2] 不是一个几乎完美排列(∣p2−p2−1∣=∣1−3∣=2\lvert p_2 - p^{-1}_2 \rvert = \lvert 1 - 3 \rvert = 2)。
  • [3,2,1][3, 2, 1] 是一个几乎完美排列。

因此,我们共得到 44 个几乎完美排列。

输入解题思路,AI测评打分。不知道怎么写?

首页