Problem p03027 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define MOD 1000003
#define INF (1 << 30)
#define LINF (1LL << 60)
#define endl "\n"
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define reprev(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--)
#define Flag(x) (1 << (x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int, int>
#define pdouble pair<double, double>
typedef unsigned long long int ull;
typedef long long lint;
long long fac[2200000], finv[2200000], inv[2200000];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < 2200000; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long facdiv(lint n, lint k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return (fac[n] * finv[k]) % MOD;
}

long long powmod(lint a, lint b) {
  return b ? powmod(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1;
}

int main(void) {
  COMinit();
  int Q;
  cin >> Q;
  rep(i, Q) {
    lint x, d, n;
    cin >> x >> d >> n;
    if (d == 1)
      cout << facdiv(x + n - 1, x - 1) << endl;
    else if (d == 0)
      cout << powmod(x, n) << endl;
    else {
      x = (x * powmod(d, MOD - 2)) % MOD;
      lint a = powmod(d, n);
      cout << (facdiv(x + n - 1, x - 1) * a) % MOD << endl;
    }
  }
}

Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define MOD 1000003
#define INF (1 << 30)
#define LINF (1LL << 60)
#define endl "\n"
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define reprev(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--)
#define Flag(x) (1 << (x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int, int>
#define pdouble pair<double, double>
typedef unsigned long long int ull;
typedef long long lint;
long long fac[2200000], finv[2200000], inv[2200000];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < 2200000; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long facdiv(lint n, lint k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return (fac[n] * finv[k]) % MOD;
}

long long powmod(lint a, lint b) {
  return b ? powmod(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1;
}

int main(void) {
  COMinit();
  int Q;
  cin >> Q;
  rep(i, Q) {
    lint x, d, n;
    cin >> x >> d >> n;
    if (d == 1)
      cout << facdiv(x + n - 1, x - 1) << endl;
    else if (d == 0)
      cout << powmod(x, n) << endl;
    else {
      x = (x * powmod(d, MOD - 2)) % MOD;
      lint a = powmod(d, n) % MOD;
      if (n > 1000003)
        cout << "0" << endl;
      else
        cout << (facdiv(x + n - 1, x - 1) * a) % MOD << endl;
    }
  }
}