排列组合公式 扳子

转载于熊猫:  http://blog.csdn.net/qq_32734731/article/details/51484729

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <iomanip>
 4 #include <cmath>
 5 #include <cstring>
 6 #include <string>
 7 #include <algorithm>
 8 using namespace std;
 9 long long mod=1000000007;
10 long long qpow(long long x,long long k)
11 {
12     long long res=1;
13     while(k)
14     {
15         if(k & 1)
16         res=res*x%mod;
17         x=x*x%mod;
18         k>>=1;
19     }
20     return res;
21 }
22 long long inv(long long a,long long x)
23 {
24     return qpow(a,x-2);
25 }
26 int ll(int x,int y)
27 {
28     long long t1=1,t2=1;
29     for(int i=x;i>y;i--)
30     {
31         t1=(t1*i)%mod;
32         t2=(t2*(i-y))%mod;
33     }
34     return t1*inv(t2,mod)%mod;
35 }
36 int main()
37 {
38     long long  n,m;
39     while(cin>>n>>m)
40     {
41         int i;
42         long long y=1;
43         int j=1;
44         if(n<m) swap(n,m);
45         cout<<ll(m+n-4,m-2)<<endl;
46     }
47     return 0;
48 }
原文地址:https://www.cnblogs.com/wangmengmeng/p/5532629.html