码迷,mamicode.com
首页 > 其他好文 > 详细

GCPC2014 A Algebraic Teamwork

时间:2015-03-15 22:41:21      阅读:381      评论:0      收藏:0      [点我收藏+]

标签:

题意:其实就是要你求排列数。

解题思路:(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\n",sum);
56     }
57     return 0;
58 }
View Code

 

GCPC2014 A Algebraic Teamwork

标签:

原文地址:http://www.cnblogs.com/zyue/p/4340488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!