Cod sursa(job #1794843)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 1 noiembrie 2016 19:32:40
Problema Dirichlet Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 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 main() {

    int n; fin >> n;

    int fact1=1, fact2=1;

    for (int i = 1; i <= n + n; ++i) {
        fact2 = (1LL*fact2*i) % mod;
        if (i == n)
            fact1 = fact2;
    }

    int sol = 1;
    sol = (1LL * sol * InvMod(n + 1)) % mod;
    sol = (1LL * sol * fact2) % mod;
    int temp = InvMod(fact1);
    sol = (1LL * sol * temp) % mod;
    sol = (1LL * sol * temp) % mod;

    fout << sol << '\n';

    return 0;

}

//Trust me, I'm the Doctor!