求C(m,n)%p得值
///利用乘法逆元:
const int MOD = 1000000007;
int inv(int a)
{
return a == 1 ? 1 : (long long)(MOD - MOD / a) * inv(MOD % a) % MOD;
}
LL C(LL n, LL m)
{
if (m < 0)
{
return 0;
}
if (n < m)
{
return 0;
}
if (m > n - m)
{
m = n - m;
}
LL up = 1, down = 1;
for (LL i = 0 ; i < m ; i ++)
{
up = up * (n - i) % MOD;
down = down * (i + 1) % MOD;
}
return up * inv(down) % MOD;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <cstring>
#include <ctime>
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const long long M = 1000000007;
const int fcnt = 100005;
long long exgcd(long long a, long long b, long long &x, long long &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
long long ans = exgcd(b, a % b, x, y);
long long temp = x;
x = y;
y = temp - (a / b) * y;
return ans;
}
long long inv(long long a)
{
long long x, y;
long long t = exgcd(a, M, x, y);
if (t != 1)
{
return -1;
}
return (x % M + M) % M;
}
long long fac[fcnt];
void getfac()
{
fac[0] = 1;
for (int i = 1; i < fcnt; i++)
{
fac[i] = fac[i - 1] * i % M;
}
}
long long C(long long n, long long m)
{
if (n < m)
{
return 0;
}
return fac[n] * inv(fac[m]) % M * inv(fac[n - m]) % M;
}
int main()
{
getfac();
ll n, m;
while (cin >> n >> m)
{
cout << C(n, m) << endl;
}
return 0;
}