Cod sursa(job #2330450)

Utilizator ionanghelinaIonut Anghelina ionanghelina Data 28 ianuarie 2019 13:39:51
Problema Dirichlet Scor 88
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include<bits/stdc++.h>
using namespace std;

const int mod=9999991;

inline void multiply(int &x,int y)
{
    long long res=(1LL*x)*(1LL*y);
    res%=mod;
    x=res;
}

inline int fastexp(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1)
        {
            multiply(res,a);
            b--;
        }
            else
        {
            multiply(a,a);
            b>>=1;
        }
    }

    return res;
}

inline int invmod(int x)
{
    return fastexp(x,mod-2);
}

int n;

int main()
{
    freopen("dirichlet.in","r",stdin);
    freopen("dirichlet.out","w",stdout);

    scanf("%d",&n);

    int sol=1;

    for(int i=n+1;i<=2*n;i++)
        multiply(sol,i);

    for(int i=1;i<=n;i++)
        multiply(sol,invmod(i));


    multiply(sol,invmod(n+1));


    printf("%d\n",sol);
    return 0;
}