[Solution] Almost Perfect Codeforces Solution
A permutation of length is called almost perfect if for all integer , it holds that , where is the inverse permutation of (i.e. if and only if ).
Count the number of almost perfect permutations of length modulo .
The first line contains a single integer () — 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 () — the length of the permutation.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output a single integer — the number of almost perfect permutations of length modulo .
For , both permutations , and are almost perfect.
For , there are only permutations. Having a look at all of them gives us:
- is an almost perfect permutation.
- is an almost perfect permutation.
- is an almost perfect permutation.
- is NOT an almost perfect permutation ().
- is NOT an almost perfect permutation ().
- is an almost perfect permutation.
So we get almost perfect permutations.
No comments:
Post a Comment