Cod sursa(job #3247215)

Utilizator Ruxandra009Ruxandra Vasilescu Ruxandra009 Data 6 octombrie 2024 12:49:21
Problema Sandokan Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream f("sandokan.in");
ofstream g("sandokan.out");

const long long mod = 2000003;
int n, k, fact[5005];

static inline long long expo(long long a, long long b)
{
    long long sol = 1;
    while(b)
        if(b % 2 == 0)
            b /= 2, a = (1LL * a * a) % mod;
        else
            b --, sol = (1LL * a * sol) % mod;

    return sol;
}

static inline long long InvMod(long long x){
    return expo(x, mod - 2);
}

int comb(int n, int k){
    return (1LL * fact[n] * (InvMod((1LL * fact[k] * fact[n - k]) % mod))) % mod;
}

int main()
{
    fact[0] = 1;
    for(int i = 1; i <= 5000; i ++)
        fact[i] = (fact[i - 1] * i) % mod;

    f >> n >> k;
    int aux = (n - 1) / (k - 1);
    aux = n - 1 - aux * (k - 1);

    g << comb(n - 1, aux);
    return 0;
}