Mathematics problem: Griffin: "What? Contest proposition. But I'm a good cook!" Sao Nian, it's not easy, just just make a math problem? So Griffin searched the network and found a problem, which can be expressed as...

Title description

Griffin: "Huh? The proposition of the competition. But I'm a good cook!"
Sao Nian, it's not easy, just just make a math problem?
So Griffin searched the network and found a problem, which can be expressed as:
for a string in the dictionary {1,2,..., n }, it is required that n! permutations from 1 to n are all substrings, ask The minimum length of such a string.
Classmate A: "Meow, meow? Can't it be more popular?"
Well, for example, suppose there is a series of n episodes, corresponding to n DVDs, and each DVD is indistinguishable and cannot be distinguished by plot content The number of DVD episodes, how many DVDs must I watch at least to ensure that I watch the series in the correct order?
For example, suppose now that n=2, we name the two DVDs 1,2, and we watch them in the order of 121, so that no matter which 1 or 2 is the real first episode, we can guarantee that we can watch continuously with the minimum number of 3 Finish the plot in the correct order.

Input data

There is an integer t (1 ≤ t ≤ 5) in the first line, which means there are t groups of data. For each set of data: the first line is a positive integer n (1 ≤ n ≤ 5).

Output Data

For each group of data, an integer is output to indicate the shortest length. The result may be large, please take the modulo of 109+7.

Sample input

2
1
2

Sample output

1
3

Experience: "n! permutations from 1 to n are all substrings of it"...... Your product

T = int(input())    
for t in range(T):      
    n = int(input())      
    result = 0      
    for n1 in range(1,n+1):          
        temp = 1          
        for n2 in range(2,n1+1):              
            temp *= n2          
        result += temp      
    print(result)  

Guess you like

Origin blog.csdn.net/tianxiefenxiang/article/details/107612726