Розбір
Transform the expression:
After removing the numbers and from the list, the number will be inserted.
If you further remove and from the list, the next number will be inserted:
By analogy, it can be stated that if initially
then at the end there will be a number .
Since initially contains integers from to , at the end there will be a number
Algorithm realization
Declare the constants.
#define MOD 1000000007 #define MAX 1000002
The input contains several test cases. Declare an array such that .
long long p[MAX];
Read the number of test cases . Compute the factorials of numbers, and store .
scanf("%d", &tests); p[1] = 1; for (i = 2; i < MAX; i++) p[i] = (p[i - 1] * i) % MOD;
Process the test cases. For each input value of print .
while (tests--) { scanf("%d", &n); printf("%lld\n", p[n + 1] - 1); }
Python realization
Declare the constants.
MOD = 1000000007 MAX = 1000002
Compute the factorials of numbers, and store .
p = [1] * MAX for i in range(2, MAX): p[i] = (p[i - 1] * i) % MOD
Read the number of test cases .
tests = int(input())
Process the test cases. For each input value of print .
for _ in range(tests): n = int(input()) print(p[n + 1] - 1)