Cod sursa(job #2896555)

Utilizator DooMeDCristian Alexutan DooMeD Data 29 aprilie 2022 23:43:11
Problema Sandokan Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

    const ll modulo = 2e6 + 3;
    const ll nmax = 5e3;

    ll fact[nmax+5]; fact[0] = 1;
    for(int i=1; i<=nmax; i++) fact[i] = 1LL * fact[i-1] * i % modulo;

    auto Pow = [](ll base, ll exp, ll mod) {
        base %= mod;
        ll temp = 1;
        while(exp) {
            if(exp&1) temp = temp * base % mod;
            base = base *  base % mod;
            exp >>= 1;
        }
        return temp;
    };

    auto Comb = [&](int N, int K) {
        return fact[N] * Pow(fact[K], modulo-2, modulo) % modulo * Pow(fact[N-K], modulo-2, modulo) % modulo;
    };

    int n, k; f >> n >> k;
    int p = (n-1) % (k-1) + 1;
    g << Comb(n-1, p-1);
    return 0;
}