Cod sursa(job #3328897)

Utilizator tileadavidtileadavid tileadavid Data 11 decembrie 2025 00:09:14
Problema Sandokan Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>
#define MOD 2000003

using namespace std;

ifstream cin ("sandokan.in");
ofstream cout ("sandokan.out");

int fact[5005];
int n, k;

void init_fact (){
    fact[1] = fact[0] = 1;
    for (int i = 2; i <= 5000; ++i){
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    }
}

int fast_expo (int b, int e){
    int x = 1;
    while (e){
        if (e % 2 == 1){
            x = (x * b) % MOD;
        }
        b = (b * b) % MOD;
        e /= 2;
    }
    return x % MOD;
}

int main()
{
    init_fact();
    cin >> n >> k;
    --k;
    int j; for (int i = 1; i <= n; ++i) cin >> j;
    int x = 0;
    while (x <= n){
        x += k;
    }
    x -= k;

    long long sol = fact[n];
    sol = (1LL * sol * fast_expo(fact[x], MOD - 2) % MOD) % MOD;
    sol = (1LL * sol * fast_expo(fact[n - x], MOD - 2) % MOD) % MOD;
    cout << sol;
//    cout << ' ' << x;
    return 0;
}