题意:其实就是要你求排列数。
解题思路:(n!-1)%1000000009
解题代码:
1 #include <iostream> 2 #include <string.h> 3 #include <stdio.h> 4 5 using namespace std; 6 typedef long long LL; 7 #define M 1000000007 8 #define maxn 100005 9 int n,m,p; 10 LL c[maxn]; 11 LL dp[maxn]; 12 LL quick_mod(LL a, LL b) 13 { 14 LL ans = 1; 15 a %= p; 16 while(b) 17 { 18 if(b & 1) 19 { 20 ans = ans * a % p; 21 b--; 22 } 23 b >>= 1; 24 a = a * a % p; 25 } 26 return ans; 27 } 28 LL C(int n) 29 { 30 LL ans = 1; 31 for(int i=1; i<= n; i++) 32 { 33 LL a = (n+1-i); 34 LL b = i ; 35 ans = ans * (a * quick_mod(b, p-2) % p) % p; 36 c[i] = ans ; 37 } 38 return ans; 39 } 40 int main() 41 { 42 int T; 43 scanf("%d", &T); 44 dp[1] = 1; 45 c[0] = 1; 46 dp[1] = 1; 47 for(int i = 2;i <= 100000;i ++ ) 48 dp[i] = (i * dp[i-1])%M; 49 while(T--) 50 { 51 p = M ; 52 scanf("%d",&n); 53 LL sum ; 54 sum = (dp[n]-1)%M; 55 printf("%lld ",sum); 56 } 57 return 0; 58 }