Cod sursa(job #3289114)

Utilizator uncle_sam_007ioan bulik uncle_sam_007 Data 25 martie 2025 18:37:36
Problema Dirichlet Scor 8
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.83 kb
#include <fstream>

using namespace std;

ifstream fin("dirichlet.in");
ofstream fout("dirichlet.out");

//catalan(n) = combinari(2n,n) - combinari(2n,n+1) = (2n)!/((n)! * (n+1)!) = (n+2) * (n+3) * ... (2n)/1*2*3*...*n

const int NMAX = 10000;
const int BASE = 1000000;
const int MOD = 9999991;

struct Huge{
    int a[NMAX];
    Huge operator = (const Huge &other){
        for(int i = 0; i <= other.a[0]; ++i){
            a[i] = other.a[i];
        }
        return *this;
    }
    Huge operator *= (int k){
        for(int i = 1; i <= a[0]; ++i){
            a[i] = a[i] * k;
        }
        int tr = 0;
        long long aux;
        for(int i = 1; i <= a[0]; ++i){
            aux = a[i] + tr;
            a[i] = aux % BASE;
            tr = aux / BASE;
        }
        while(tr){
            a[0] ++;
            a[a[0]] = tr % BASE;
            tr = tr / BASE;
        }
        return *this;
    }
    Huge operator /= (int k){
        int tr = 0;
        long long aux;
        for(int i = a[0]; i >= 1; --i){
            aux = 1LL * tr * BASE + a[i];
            a[i] = aux / k;
            tr = aux % k;
        }
        while(a[0] > 1 && a[a[0]] ==0){
            a[0] --;
        }
        return *this;
    }
    int operator % (int k){
        int i, r = 0;
        for (i = a[0]; i >= 1; i --)
            r = (r * 10 + a[i]) % k;
        return r;
    }
    void display(){
        for(int i = a[0]; i >= 1; --i){
            fout << a[i] % BASE;
        }
    }
};

void solve(){
    int n;
    fin >> n;
    Huge rez;
    rez.a[0] = 1;
    rez.a[1] = 1;
    for(int i = 1; i < n; ++i){
        rez *= (n + 1 + i);
        rez /= i;
    }
    rez /= n;
    int ret = rez % MOD;
    //rez.display();
    fout << ret;
}

int main()
{
    solve();
    return 0;
}