Cod sursa(job #1796754)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 3 noiembrie 2016 18:58:52
Problema Dirichlet Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<fstream>
#define mod 9999991
using namespace std;
int n, i, sol, f1, f2, x, y;
ifstream fin("dirichlet.in");
ofstream fout("dirichlet.out");
void invmod(int a, int b, int &x, int &y){
    if(b == 0){
        x = 1;
        y = 0;
    }
    else{
        int x2, y2;
        invmod(b, a % b, x2, y2);
        x = y2;
        y = x2 - a / b * y2;
    }
}
int main(){
    fin>> n;
    f1 = f2 = 1;
    for(i = 1; i <= n + n; i++){
        f1 = f1 * 1LL * i % mod;
        if(i == n){
            f2 = f1;
        }
    }
    f2 = f2 * 1LL * f2 % mod * (n + 1) % mod;
    invmod(f2, mod, x, y);
    x %= mod;
    if(x < 0){
        x += mod;
    }
    sol = f1 * 1LL * x % mod;
    fout<< sol <<"\n";
    return 0;
}