Cod sursa(job #2763849)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 17 iulie 2021 11:02:45
Problema Sandokan Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("sandokan.in");
ofstream fout("sandokan.out");

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

int log2pow(int a, int b){
    if (b == 1){
        return a;
    }
    int x = log2pow(a, b / 2);
    if (b % 2 == 0){
        return 1LL * x * x % mod;
    }
    return 1LL * x * x % mod * a % mod;
}

int main(){
    fin >> n >> k;
    for (int i = 1; i <= n; ++i){
        int x;
        fin >> x;
    }
    int ans = 1;
    fact[0] = 1;
    for (int i = 1; i <= n; ++i){
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    ans = fact[n - 1];
    int x = n - 1 - ((n - 1) / (k - 1)) * (k - 1);
    ans = 1LL * ans * log2pow(fact[x], mod - 2) % mod;
    ans = 1LL * ans * log2pow(fact[n - 1 - x], mod - 2) % mod;
    fout << ans;
    return 0;
}