Cod sursa(job #1794840)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 1 noiembrie 2016 19:30:38
Problema Dirichlet Scor 96
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

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

const int mod = 9999991;

void Euclid(int a, int b, int& x, int& y) {

    if (!b) {
        x=1, y=0;
        return;
    }

    int xa, ya;
    Euclid(b, a%b, xa, ya);

    x = ya;
    y = xa - (a/b)*ya;

}

int InvMod(int val) {

    int x, y;
    Euclid(mod, val, x, y);

    y %= mod;
    if (y < 0) y += mod;

    return y;

}

int Factorial(int n) {

    int ret = 1;
    for (int i = 1; i <= n; ++i)
        ret = (1LL*ret*i) % mod;
    return ret;

}

int main() {

    int n; fin >> n;

    int sol = 1;
    sol = (1LL * sol * InvMod(n + 1)) % mod;
    sol = (1LL * sol * Factorial(2 * n)) % mod;
    int temp = InvMod(Factorial(n));
    sol = (1LL * sol * temp) % mod;
    sol = (1LL * sol * temp) % mod;

    fout << sol << '\n';

    return 0;

}

//Trust me, I'm the Doctor!