Cod sursa(job #638366)

Utilizator MciprianMMciprianM MciprianM Data 20 noiembrie 2011 20:34:39
Problema Dirichlet Scor 8
Compilator cpp Status done
Runda .com 2011 Marime 0.64 kb
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

const ll mod = 9999991ll;

void cmmdc(ll a, ll b, ll &x, ll &y){
  if(b){
	cmmdc(b,a%b,x,y);
	long long aux=y;
	y=x-(a/b)*y;
	x=aux;
  }
  else
  {
		x=1;
		y=0;
  }
}

ll invers (ll a, ll n) {
	ll x, y;
	cmmdc(a,n,x,y);
	while(x<0)  x+=n;
	return x;
}



int main () {
	ll n, i, t1, t2;
	freopen ("dirichlet.in", "rt", stdin);
	freopen ("dirichlet.out", "wt", stdout);
	cin >> n;
	t1 = t2 = 1;
	for (i = 2; i <= n; ++ i) {
		t1 = (t1 * (n + i)) % mod;
		t2 = t2 * i;
	}
	t2 = invers (t2, mod);
	t1 = (t1 * t2) % mod;
	cout << t1 << endl;
	return 0;
}