Chess
Accepts: 1805
Submissions: 5738
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
答案就是C(max(n, m), min(n, m))
不用Lucas也行
#include<stdio.h>
#include<algorithm>
using namespace std;
#define LL long long
LL Pow(LL a, LL b, LL mod);
LL C(LL m, LL n, LL p);
LL Pow(LL a, LL b, LL mod)
{
LL sum;
sum = 1;
while(b)
{
if(b%2==1)
sum = (sum*a)%mod;
a = (a*a)%mod;
b /= 2;
}
return sum;
}
LL C(LL m, LL n, LL p)
{
LL i, ans;
ans = 1;
if(m<n)
return 0;
for(i=1;i<=n;i++)
ans = ans*(((m-n+i)%p)*Pow(i, p-2, p)%p)%p;
return ans;
}
int main(void)
{
LL T, n, m;
scanf("%I64d", &T);
while(T--)
{
scanf("%I64d%I64d", &n, &m);
if(n>m)
swap(n, m);
printf("%I64d\n", C(m, n, 1000000007));
}
return 0;
}