Pagini recente » Cod sursa (job #2654272) | Cod sursa (job #934260) | Cod sursa (job #2329441) | Cod sursa (job #3189861) | Cod sursa (job #3247215)
#include <fstream>
#include <vector>
using namespace std;
ifstream f("sandokan.in");
ofstream g("sandokan.out");
const long long mod = 2000003;
int n, k, fact[5005];
static inline long long expo(long long a, long long b)
{
long long sol = 1;
while(b)
if(b % 2 == 0)
b /= 2, a = (1LL * a * a) % mod;
else
b --, sol = (1LL * a * sol) % mod;
return sol;
}
static inline long long InvMod(long long x){
return expo(x, mod - 2);
}
int comb(int n, int k){
return (1LL * fact[n] * (InvMod((1LL * fact[k] * fact[n - k]) % mod))) % mod;
}
int main()
{
fact[0] = 1;
for(int i = 1; i <= 5000; i ++)
fact[i] = (fact[i - 1] * i) % mod;
f >> n >> k;
int aux = (n - 1) / (k - 1);
aux = n - 1 - aux * (k - 1);
g << comb(n - 1, aux);
return 0;
}