Pagini recente » Cod sursa (job #621288) | Cod sursa (job #33684) | Cod sursa (job #2098107) | miau | Cod sursa (job #2896555)
#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;
}