Cod sursa(job #1090416)

Utilizator CosminRusuCosmin Rusu CosminRusu Data 22 ianuarie 2014 18:04:17
Problema Dirichlet Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.44 kb
/// (N + 2)(N + 3)...(N + N) / N!
#include <fstream>
#include <vector>
#include <bitset>

using namespace std;

const char infile[] = "dirichlet.in";
const char outfile[] = "dirichlet.out";

ifstream fin(infile);
ofstream fout(outfile);

const int MAXN = 4005;
const int oo = 0x3f3f3f3f;
const int MOD = 9999991;

typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;

const inline int min(const int &a, const int &b) { if( a > b ) return b;   return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b;   return a; }
const inline void Get_min(int &a, const int b)    { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b)    { if( a < b ) a = b; }

inline int lgPower(const int &A, const int &N) {
    /// A ^ N
    if(N == 1)
        return A;
    int aux = (1LL * A * A) % MOD;
    if(N & 1)
        return (1LL * A * lgPower(aux, (N - 1) / 2)) % MOD;
    return lgPower(aux, N / 2);
}

inline int invMod(const int &value) {
    return lgPower(value, MOD - 2);
}

int main() {
    int N, factN = 1, factNplus = 1;
    bool ok = false;
    fin >> N;
    for(int i = 1 ; i <= N ; ++ i) {
        if(i == 2)
            ok = true;
        if(ok)
            factNplus = (1LL * factNplus * (N + i)) % MOD;
        factN = (1LL * factN * i) % MOD;
    }
    fout << (1LL * factNplus * invMod(factN)) % MOD << "\n";
    fin.close();
    fout.close();
    return 0;
}