GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday, 6 September 2022

[Solution] Almost Perfect Codeforces Solution



E. Almost Perfect
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A permutation p of length n is called almost perfect if for all integer 1in, it holds that |pipi1|1, where p1 is the inverse permutation of p (i.e. pk11=k2 if and only if pk2=k1).

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

Input

The first line contains a single integer t (1t1000) — 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 (1n3105) — the length of the permutation.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

It is guaranteed that the sum of n over all test cases does not exceed 3105.

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 (|p2p21|=|31|=2).
  • [3,1,2] is NOT an almost perfect permutation (|p2p21|=|13|=2).
  • [3,2,1] is an almost perfect permutation.

So we get 4 almost perfect permutations.

No comments:

Post a Comment