Cod sursa(job #2098051)

Utilizator PopoviciRobertPopovici Robert PopoviciRobert Data 2 ianuarie 2018 11:44:44
Problema Sandokan Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>

using namespace std;

const int MOD = (int) 2e6 + 3;
const int MAXN = 5000;

int fact[MAXN + 1];

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1)
            ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

inline int comb(int n, int k) {
    return (1LL * fact[n] * lgput((1LL * fact[k] * fact[n - k]) % MOD, MOD - 2)) % MOD;
}

int main() {
    ifstream cin("sandokan.in");
    ofstream cout("sandokan.out");
    int i, n, k;
    ios::sync_with_stdio(false);
    cin >> n >> k;
    int aux = n;
    while(aux >= k) {
        aux -= (k - 1);
    }
    fact[0] = 1;
    for(i = 1; i <= n; i++) {
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    }
    cout << comb(n - 1, aux - 1);
    cin.close();
    cout.close();
    return 0;
}