B. Marin and Anti-coprime Permutation
Marin wants you to count number of permutations that are beautiful. A beautiful permutation of length is a permutation that has the following property:
A permutation is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array) and is also not a permutation ( but there is in the array).
The first line contains one integer () — the number of test cases.
Each test case consists of one line containing one integer ().
For each test case, print one integer — number of beautiful permutations. Because the answer can be very big, please print the answer modulo .
7
1
2
3
4
5
6
1000
0
1
0
4
0
36
665702330
In first test case, we only have one permutation which is but it is not beautiful because .
In second test case, we only have one beautiful permutation which is because .
solution
- #include<iostream>
- #include<algorithm>
- #include<cmath>
- #include<ctime>
- #include<vector>
- #define ll long long
- using namespace std;
- void solve()
- {
- //B. Marin and Anti-coprime Permutation
- ll n;
- cin >> n;
- if (n % 2 ==1)
- {
- cout << 0 << "\n";
- }
- else
- {
- ll sum = 1;
- for (int i = 1; i <= n / 2; i++)
- {
- sum = (i * sum) % 998244353;
- }
- sum *= sum;
- cout << sum % 998244353 << "\n";
- }
- }
- int main()
- {
- int t;
- cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
No comments:
Post a Comment