Problem G. Cyclic

Problem Description

Count the number of cyclic permutations of length n with no continuous subsequence [i, i + 1 mod n].
Output the answer modulo 998244353.

Input

The first line of the input contains an integer T , denoting the number of test cases.
In each test case, there is a single integer n in one line, denoting the length of cyclic permutations.
1 ≤ T ≤ 20, 1 ≤ n ≤ 100000

Output

For each test case, output one line contains a single integer, denoting the answer modulo 998244353.

Sample Input

3 4 5 6

Sample Output

1 8 36

考虑容斥定理,这里主要说一下,怎样拓展

比如说 k=2的时候, 我们可能选  12 23,这种连着的,还有可能选 12 45,这种不连着的

那么首先 第一种情况 【n-(k+1)】!正常操作,

对于第二种来说,那个45又可以当做一个整体的元素来跑 ,所以就是 【n-(k+1)-1+1】!,发现还是【n-(k+1)】!,

可以推广到k,然后,就是容斥的基本操作了

#include
using namespace std;

typedef long long LL;
#define rep(i,a,b) for(int i=a;i>=1;
	}
	return ans%mod;
}
void init(){
    F[0]=1;
    for(int i=1;i

 

你可能感兴趣的:(....容斥原理)