Cod sursa(job #637668)

Utilizator rootsroots1 roots Data 20 noiembrie 2011 15:52:33
Problema Dirichlet Scor 100
Compilator cpp Status done
Runda .com 2011 Marime 0.89 kb
#include <fstream>

#define MOD 9999991

using namespace std;

inline void euclid(long long a,long long b,long long &x,long long &y)
{
    long long x0,y0;

    if(b==0)
    {
        x=1;
        y=0;
    }
    else
    {
        euclid(b,a%b,x0,y0);
        x=y0;
        y=x0-(a/b)*y0;
    }
}

ifstream in;
ofstream out;

int main()
{
    long long v,w;
    long long x,y;
    int N;

    in.open("dirichlet.in");
    in>>N;
    in.close();

    v=1;
    for(int i=N+2;i<=2*N;++i)
    {
        v*=i;
        v%=MOD;
    }

    w=1;
    for(int i=2;i<=N;++i)
    {
        w*=i;
        w%=MOD;
    }

    x=0;
    y=0;

    int aux=MOD;
    euclid(w,aux,x,y);

    if(x<0)
    {
        y=x;
        x+=(y/MOD)*MOD;
        if(y%MOD) x+=MOD;
    }

    out.open("dirichlet.out");
    out<<(x*v)%MOD<<'\n';
    out.close();

    return 0;
}