Cod sursa(job #2639806)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 3 august 2020 23:11:49
Problema Sandokan Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <bits/stdc++.h>
#define MOD 2000003
#define int long long

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 = (ans * x) % MOD;
    x = (x * x) % MOD;
    exp /= 2;
  }
  return ans % MOD;
}

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

int N, K;

int32_t main () {
  fin >> N >> K;
  if (N <= K)
    fout << "1\n";
  else {
    int ans = (Factorial (N - 1) * Invers (Factorial ((N - 1) % (K - 1)))) % MOD;
    ans = (ans * Invers (Factorial (N - (N - 1) % (K - 1)) - 1)) % MOD;
    fout << ans;
  }

}