插空法
hnahongyi
2023-11-11 11:46:09
#include<bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const int MOD = 1e9 + 7;
long long f[N];
long long qpow(int x, int n) {
if (n == 0) return 1;
long long tmp = qpow(x, n / 2);
tmp = tmp * tmp % MOD;
if (n % 2 == 1) return tmp * x % MOD;
else return tmp % MOD;
}
int main() {
int n;
int k;
cin >> n >> k;
f[0] = 1;
for (int i = 1; i <= n; i++) {
f[i] = f[i - 1] * i % MOD;
}
cout << f[n - k + 1]*qpow(f[k], MOD - 2) % MOD*qpow(f[n - k + 1 - k], MOD - 2) % MOD;
return 0;
}