Cod sursa(job #2639802)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 3 august 2020 22:56:58
Problema Sandokan Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <bits/stdc++.h>
#define MOD 2000003

using namespace std;

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

int Invers (int x) {
  int exp = MOD - 2, ans = 1;
  while (exp) {
    if (exp & 1)
      ans = (1LL * ans * x) % MOD;
    x = (1LL * x * x) % MOD;
    exp /= 2;
  }
  return ans;
}

int Factorial (int n) {
  if (n == 0)
    return 1;
  return (1LL * n * Factorial (n - 1)) % MOD;
}

int N, K;

int main () {
  fin >> N >> K;
  int x = N - 1;
  while (x >= K - 1)
    x -= (K - 1);
  int ans = (1LL * Factorial (N - 1) * Invers (Factorial (x))) % MOD;
  ans = (1LL * ans * Invers (Factorial (N - x + 1))) % MOD;
  fout << ans;
}