Expected Weight
Given a sequence
of length , the weight of this sequence is defined as
Given an integer , we pick a permutation of uniformly at random. What is the expected weight of this permutation?
It can be shown that the answer can be represented as where and are coprime integers and . Print the value of modulo .
Input Format
- First line of the input contains , the number of test cases. Then the test cases follow.
- Each test case contains a single integer on a single line .
Output Format
For each test case, print a single integer, the answer to the test case.
Constraints
Subtasks
- Subtask 1 (100 points): Original constraints
Sample Input 1
3
1
2
3
Sample Output 1
1
499122181
12
Explanation
- Test case : There is only one permutation of which is and the weight of this permutation is equal to . So, the expected weight is equal to .
- Test case : There are permutations of namely
- with weight equal to .
- with weight equal to .
So, the expected weight is equal to .
- Test case There are permutations of namely
- with weight equal to .
- with weight equal to .
- with weight equal to .
- with weight equal to .
- with weight equal to .
- with weight equal to .
So, the expected weight is equal to .
Code?
ReplyDelete