Codeforces 57C Array

#define _CRT_SECURE_NO_WARNINGS
#include 
#include 
#include 
#include 
#include 
#include 
#define ll long long

using namespace std;
const int mod = 1000000007;

ll fact(ll n, ll p) {//n的阶乘求余p 
	ll ret = 1;
	for (ll i = 1; i <= n; i++) ret = ret * i % p;
	return ret;
}
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) {
	if (!b) { d = a, x = 1, y = 0; }
	else {
		ex_gcd(b, a % b, y, x, d);
		y -= x * (a / b);
	}
}
ll inv(ll t, ll p) {//如果不存在,返回-1 //求逆元 
	ll d, x, y;
	ex_gcd(t, p, x, y, d);
	return d == 1 ? (x % p + p) % p : -1;
}
ll comb(ll n, ll m, ll p) {//C(n, m) % p
	if (m < 0 || m > n) return 0;
	return fact(n, p) * inv(fact(m, p), p) % p * inv(fact(n - m, p), p) % p;
}

ll Lucas(ll n, ll m, ll p) {//Lucas定理求C(n, m) % p 
	return m ? Lucas(n / p, m / p, p) * comb(n%p, m%p, p) % p : 1;
}

int n;

int main() {
	scanf("%d", &n);
	printf("%lld\n", (2 * Lucas(2 * n - 1, n, mod) % mod - n));
	//system("pause");
	return 0;
}

 

你可能感兴趣的:(ACM)