Cod sursa(job #635707)

Utilizator crushackPopescu Silviu crushack Data 19 noiembrie 2011 14:23:20
Problema Dirichlet Scor 100
Compilator cpp Status done
Runda .com 2011 Marime 0.74 kb
#include <stdio.h>

typedef long long ll;
const char IN[]="dirichlet.in",OUT[]="dirichlet.out";
const int mod = 9999991;

int N,doiN;
int PN,PdoiN;

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

int inv(int x){
	ll inv,ins;
	gcd(inv,ins,x,mod);
	if (inv<=0)
		inv= mod + inv%mod;
	return inv;
}

void perm()
{
	int i,p=1;
	
	for (i=1;i<=doiN;++i)
	{
		p=1LL*i*p%mod;
		if (i==N) PN=p;
	}
	PdoiN=p;
}

int main()
{
	freopen(IN,"r",stdin);
	scanf("%d",&N);doiN=2*N;
	fclose(stdin);
	
	perm();
	//printf("%d %d\n",PdoiN,PN);
	int rez= (1LL*PdoiN*inv(PN))%mod*(ll)inv(PN)%mod*(ll)inv(N+1)%mod;
	
	freopen(OUT,"w",stdout);
	printf("%d\n",rez);
	fclose(stdout);
	
	return 0;
}