#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 nn, the maximum value of the perfect length among all permutations of 11 to nn is called the nn-th order maximum perfect length.

Given a positive integer nn, compute the sum of the values of all perfect subsequences whose length is exactly the nn-th order maximum perfect length, over all permutations of 11 to nn.

Input Format

Each test case contains multiple queries. The queries are independent of each other.

The first line contains an integer TT, representing the number of queries.

The next TT lines each contain an integer nn, representing the given nn.

Output Format

Output TT 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 10000000071000000007 (i.e. 109+710^{9}+7).

5
1
2
3
5
10
1
3
21
140
2268000

Hint

Sample Explanation

When n=1n=1, the answer is obviously 11.

When n=2n=2, all permutations include (1,2)(1,2) and (2,1)(2,1). Among them, (2,1)(2,1) has the longest perfect subsequence, which is (2,1)(2,1) itself. The 22-nd order maximum perfect length is 22, so the answer is 2+12+1.

When n=3n=3, all permutations include (1,2,3)(1,2,3), (1,3,2)(1,3,2), (2,1,3)(2,1,3), (2,3,1)(2,3,1), (3,1,2)(3,1,2), (3,2,1)(3,2,1). Among them, (2,1)(2,1) and (3,1)(3,1) are both longest perfect subsequences, and the 33-rd order maximum perfect length is 22.

Sequences (1,2,3)(1,2,3) and (1,3,2)(1,3,2) have no perfect subsequence of length 22.

Sequence (2,1,3)(2,1,3) has the perfect subsequence (2,1)(2,1), with a total value sum of 33.

Sequence (2,3,1)(2,3,1) has perfect subsequences (2,1)(2,1) and (3,1)(3,1), with a total value sum of 77.

Sequence (3,1,2)(3,1,2) has the perfect subsequence (3,1)(3,1), with a total value sum of 44.

Sequence (3,2,1)(3,2,1) has perfect subsequences (2,1)(2,1) and (3,1)(3,1), with a total value sum of 77.

The answer is 3+7+4+7=213+7+4+7=21.

Constraints and Notes

For 10%10\% of the testdata, n10n \leq 10.

For 20%20\% of the testdata, n20n \leq 20.

For 30%30\% of the testdata, T20,n1000T \leq 20, n \leq 1000.

For 40%40\% of the testdata, T20,n105T \leq 20, n \leq 10^{5}.

For all testdata, 1T105,1n1061 \leq T \leq 10^{5}, 1 \leq n \leq 10^{6}.

Lanqiao Cup 2021, Second Round Provincial Contest, Group A, Problem J.

Translated by ChatGPT 5