Cod sursa(job #638490)

Utilizator darrenRares Buhai darren Data 20 noiembrie 2011 21:52:56
Problema Dirichlet Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>

using namespace std;

const int MOD = 9999991;
int N, fact[2000002];

inline int power(int x, int y)
{
	if (y == 0) return 1;
	if (y % 2 == 0) return power(1LL * x * x % MOD, y >> 1);
	return (1LL * x * power(1LL * x * x % MOD, y >> 1)) % MOD;
}
inline int inv(int x)
{
	return power(x, MOD - 2);
}
inline int comb(int x, int y)
{
	return 1LL * (1LL * fact[x] * inv(fact[x - y]) % MOD) * inv(fact[y]) % MOD;
}

int main()
{
	ifstream fin("dirichlet.in");
	ofstream fout("dirichlet.out");
	
	fact[0] = 1;
	for (int i = 1; i <= 2000000; ++i)
		fact[i] = 1LL * fact[i - 1] * i % MOD;
	
	fin >> N;
	
	int result = comb(2 * N, N) - comb(2 * N, N + 1);
	if (result < 0) result += MOD;
	
	fout << result;
	
	fin.close();
	fout.close();
}