Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define dbg(x) cerr << #x ": " << x << "\n"
#define dbg_p(x) cerr << #x ": " << x.first << "," << x.second << "\n"
#define dbg_v(x, n)                                                            \
  do {                                                                         \
    cerr << #x "[]: ";                                                         \
    for (int _ = 0; _ < n; ++_)                                                \
      cerr << x[_] << " ";                                                     \
    cerr << '\n';                                                              \
  } while (0)
#define dbg_ok cerr << "OK!\n"

#define st first
#define nd second

using namespace std;

const long long N = 300100;
const long long MOD = 998244353;
long long n, k, a, b, f[N];

template <class T> ostream &operator<<(ostream &out, vector<T> v) {
  out << v.size() << '\n';
  for (auto e : v)
    out << e << ' ';
  return out;
}

long long powMod(long long b, long long e) {
  if (e == 0)
    return 1;
  if (e == 1)
    return b;

  long long t = powMod(b, e / 2);
  t = (t * t) % MOD;
  if (e % 2)
    return (t * b) % MOD;
  return t;
}

long long invMod(long long k) { return powMod(k, MOD - 2); }

long long comb(long long n, long long k) {
  return (f[n] * invMod(((f[k] * f[n - k]) % MOD))) % MOD;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> a >> b >> k;

  f[0] = 1;
  for (int i = 1; i <= n; i++)
    f[i] = (f[i - 1] * i) % MOD;
  long long ans = 0;
  for (long long i = 0; i <= n; i++) {
    long long r = k - i * a;
    if (r < 0)
      break;
    if (r % b == 0) {
      long long y = r / b;
      ans += comb(n, i) * comb(n, y);
      ans %= MOD;
    }
  }

  cout << ans << '\n';
}

Fixed submission:
#include <bits/stdc++.h>

#define dbg(x) cerr << #x ": " << x << "\n"
#define dbg_p(x) cerr << #x ": " << x.first << "," << x.second << "\n"
#define dbg_v(x, n)                                                            \
  do {                                                                         \
    cerr << #x "[]: ";                                                         \
    for (int _ = 0; _ < n; ++_)                                                \
      cerr << x[_] << " ";                                                     \
    cerr << '\n';                                                              \
  } while (0)
#define dbg_ok cerr << "OK!\n"

#define st first
#define nd second

using namespace std;

const long long N = 300100;
const long long MOD = 998244353;
long long n, k, a, b, f[N];

template <class T> ostream &operator<<(ostream &out, vector<T> v) {
  out << v.size() << '\n';
  for (auto e : v)
    out << e << ' ';
  return out;
}

long long powMod(long long b, long long e) {
  if (e == 0)
    return 1;
  if (e == 1)
    return b;

  long long t = powMod(b, e / 2);
  t = (t * t) % MOD;
  if (e % 2)
    return (t * b) % MOD;
  return t;
}

long long invMod(long long k) { return powMod(k, MOD - 2); }

long long comb(long long n, long long k) {
  return (f[n] * invMod(((f[k] * f[n - k]) % MOD))) % MOD;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> a >> b >> k;

  f[0] = 1;
  for (int i = 1; i <= n; i++)
    f[i] = (f[i - 1] * i) % MOD;
  long long ans = 0;
  for (long long i = 0; i <= n; i++) {
    long long r = k - i * a;
    if (r < 0)
      break;
    if (r % b == 0) {
      long long y = r / b;
      if (y > n)
        continue;
      ans += comb(n, i) * comb(n, y);
      ans %= MOD;
    }
  }

  cout << ans << '\n';
}