A special site for solving fun programming problems and challenges, interested in computer science, programming, basics, data structure and algorithms

 B. Marin and Anti-coprime Permutation

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output


Marin wants you to count number of permutations that are beautiful. A beautiful permutation of length n is a permutation that has the following property:

gcd(1p1,2p2,,npn)>1,
where gcd is the greatest common divisor.

A permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).

Input

The first line contains one integer t (1t103) — the number of test cases.

Each test case consists of one line containing one integer n (1n103).

Output

For each test case, print one integer — number of beautiful permutations. Because the answer can be very big, please print the answer modulo 998244353.

Example
input
Copy
7
1
2
3
4
5
6
1000
output
Copy
0
1
0
4
0
36
665702330
Note

In first test case, we only have one permutation which is [1] but it is not beautiful because gcd(11)=1.

In second test case, we only have one beautiful permutation which is [2,1] because gcd(12,21)=2.



solution

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cmath>
  4. #include<ctime>
  5. #include<vector>
  6. #define ll long long
  7. using namespace std;
  8.  
  9. void solve()
  10. {
  11. //B. Marin and Anti-coprime Permutation
  12.  
  13. ll n;
  14. cin >> n;
  15. if (n % 2 ==1)
  16. {
  17. cout << 0 << "\n";
  18. }
  19. else
  20. {
  21. ll sum = 1;
  22. for (int i = 1; i <= n / 2; i++)
  23. {
  24. sum = (i * sum) % 998244353;
  25. }
  26. sum *= sum;
  27. cout << sum % 998244353 << "\n";
  28. }
  29. }
  30.  
  31. int main()
  32. {
  33. int t;
  34. cin >> t;
  35. while (t--)
  36. {
  37. solve();
  38. }
  39. return 0;
  40. }

No comments:

Post a Comment