#P8757. [蓝桥杯 2021 省 A2] 完美序列
[蓝桥杯 2021 省 A2] 完美序列
Problem Description
Selecting some elements from a sequence and keeping their original order to form a new sequence is called a subsequence of the sequence. The value of a subsequence is the sum of all elements in the subsequence.
If a sequence is monotonically decreasing, and every number except the first one is a factor of the previous number, then this sequence is called a perfect sequence.
If a subsequence of a sequence is a perfect sequence, then it is called a perfect subsequence of the sequence. The length of the longest perfect subsequence of a sequence is called the perfect length of the sequence.
Given a positive integer , the maximum value of the perfect length among all permutations of to is called the -th order maximum perfect length.
Given a positive integer , compute the sum of the values of all perfect subsequences whose length is exactly the -th order maximum perfect length, over all permutations of to .
Input Format
Each test case contains multiple queries. The queries are independent of each other.
The first line contains an integer , representing the number of queries.
The next lines each contain an integer , representing the given .
Output Format
Output lines, in order, each corresponding to the answer for one query.
Each line contains one integer, which is the remainder of the corresponding answer modulo (i.e. ).
5
1
2
3
5
10
1
3
21
140
2268000
Hint
Sample Explanation
When , the answer is obviously .
When , all permutations include and . Among them, has the longest perfect subsequence, which is itself. The -nd order maximum perfect length is , so the answer is .
When , all permutations include , , , , , . Among them, and are both longest perfect subsequences, and the -rd order maximum perfect length is .
Sequences and have no perfect subsequence of length .
Sequence has the perfect subsequence , with a total value sum of .
Sequence has perfect subsequences and , with a total value sum of .
Sequence has the perfect subsequence , with a total value sum of .
Sequence has perfect subsequences and , with a total value sum of .
The answer is .
Constraints and Notes
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For all testdata, .
Lanqiao Cup 2021, Second Round Provincial Contest, Group A, Problem J.
Translated by ChatGPT 5