Language: C++

#include <bits/stdc++.h>

#define int int64_t

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int64_t const MOD = 998244353;

namespace math { namespace integer {

template<class T> T mod_mul(T x, T k, ll m) { if(k == 0) { return 0; } if(k % 2 == 0) { return mod_mul((x+x) % m, k/2, m); } else { return (x + mod_mul(x, k-1, m)) % m; } }
template<class T> T mod_pow(T x, T n, ll mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(mod_mul(x, x, mod) % mod, n / 2, mod); } else { return mod_mul(x, mod_pow(x, n - 1, mod), mod); } }
template<class T> T extgcd(T a, T b, T& x, T& y) { T d = a; if(b != 0) { d = extgcd(b, a%b, y, x); y -= (a / b) * x;} else { x = 1, y = 0; } return d; }
template<class T> T mod_inverse(T x, ll mod) { return mod_pow(x, T(mod-2), mod); /* use fermat */ }
template<class T> T mod_inverse_composite_num_mod(T a, ll mod) { T x, y; extgcd(a, mod, x, y); return (mod + x % mod) % mod; }

}
using namespace integer;
}
using namespace math;

namespace math {

constexpr int64_t MaxFact = 300010;

template<class T = int64_t>
struct FactRevFactList {

  array<T, MaxFact+1> fact_;
  array<T, MaxFact+1> rev_fact_;

  FactRevFactList() {
    fact_[0] = 1;
    for(int i=1; i<MaxFact; i++) {
      fact_[i] = fact_[i-1] * i;
      fact_[i] %= MOD;
    }

    rev_fact_[MaxFact-1] = mod_pow(fact_[MaxFact-1], (T)MOD-2, MOD);

    for(int i=MaxFact-2; i>=0; i--) {
      rev_fact_[i] = rev_fact_[i+1] * (i+1);
      rev_fact_[i] %= MOD;
    }
  }

  T fact(int x) const { return fact_[x]; }
  T fact_inv(int x) const { return rev_fact_[x]; }

};

template<class T = int64_t>
struct CombinationBig {
  math::FactRevFactList<> fr_;
  T comb(T n, T r) { return (fr_.fact(n) * fr_.fact_inv(r) % MOD) * fr_.fact_inv(n-r) % MOD; }
};

}

math::CombinationBig<> cbig;

signed main() {
  int64_t N, A, B, K;
  cin >> N >> A >> B >> K;
  int64_t ans = 0;
  rep(a, N + 1) {
    auto rest = K - A * a;
    if (rest < 0) continue;
    auto b = rest / B;
    if (rest % B == 0 && b <= N) {
      ans += cbig.comb(N, a) * cbig.comb(N, b) % MOD;
      ans %= MOD;
    }
  }
  cout << ans << endl;
}


Compiler output:
a.cc: In instantiation of 'T math::integer::mod_pow(T, T, ll) [with T = long int; ll = long long int]':
a.cc:52:35:   required from 'math::FactRevFactList<T>::FactRevFactList() [with T = long int]'
   52 |     rev_fact_[MaxFact-1] = mod_pow(fact_[MaxFact-1], (T)MOD-2, MOD);
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:66:8:   required from here
   66 | struct CombinationBig {
      |        ^~~~~~~~~~~~~~
a.cc:25:105: error: no matching function for call to 'mod_pow(long long int, long int, ll&)'
   25 | template<class T> T mod_pow(T x, T n, ll mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(mod_mul(x, x, mod) % mod, n / 2, mod); } else { return mod_mul(x, mod_pow(x, n - 1, mod), mod); } }
      |                                                                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:25:21: note: candidate: 'template<class T> T math::integer::mod_pow(T, T, ll)'
   25 | template<class T> T mod_pow(T x, T n, ll mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(mod_mul(x, x, mod) % mod, n / 2, mod); } else { return mod_mul(x, mod_pow(x, n - 1, mod), mod); } }
      |                     ^~~~~~~
a.cc:25:21: note:   template argument deduction/substitution failed:
a.cc:25:105: note:   deduced conflicting types for parameter 'T' ('long long int' and 'long int')
   25 | template<class T> T mod_pow(T x, T n, ll mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(mod_mul(x, x, mod) % mod, n / 2, mod); } else { return mod_mul(x, mod_pow(x, n - 1, mod), mod); } }
      |                                                                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In instantiation of 'T math::integer::mod_mul(T, T, ll) [with T = long int; ll = long long int]':
a.cc:25:113:   required from 'T math::integer::mod_pow(T, T, ll) [with T = long int; ll = long long int]'
   25 | template<class T> T mod_pow(T x, T n, ll mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(mod_mul(x, x, mod) % mod, n / 2, mod); } else { return mod_mul(x, mod_pow(x, n - 1, mod), mod); } }
      |                                                                                                          ~~~~~~~^~~~~~~~~~~
a.cc:52:35:   required from 'math::FactRevFactList<T>::FactRevFactList() [with T = long int]'
   52 |     rev_fact_[MaxFact-1] = mod_pow(fact_[MaxFact-1], (T)MOD-2, MOD);
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:66:8:   required from here
   66 | struct CombinationBig {
      |        ^~~~~~~~~~~~~~
a.cc:24:103: error: no matching function for call to 'mod_mul(long long int, long int, ll&)'
   24 | template<class T> T mod_mul(T x, T k, ll m) { if(k == 0) { return 0; } if(k % 2 == 0) { return mod_mul((x+x) % m, k/2, m); } else { return (x + mod_mul(x, k-1, m)) % m; } }
      |                                                                                                ~~~~~~~^~~~~~~~~~~~~~~~~~~
a.cc:24:21: note: candidate: 'template<class T> T math::integer::mod_mul(T, T, ll)'
   24 | template<class T> T mod_mul(T x, T k, ll m) { if(k == 0) { return 0; } if(k % 2 == 0) { return mod_mul((x+x) % m, k/2, m); } else { return (x + mod_mul(x, k-1, m)) % m; } }
      |                     ^~~~~~~
a.cc:24:21: note:   template argument deduction/substitution failed:
a.cc:24:103: note:   deduced conflicting types for parameter 'T' ('long long int' and 'long int')
   24 | template<class T> T mod_mul(T x, T k, ll m) { if(k == 0) { return 0; } if(k % 2 == 0) { return mod_mul((x+x) % m, k/2, m); } else { return (x + mod_mul(x, k-1, m)) % m; } }
      |                                                                                                ~~~~~~~^~~~~~~~~~~~~~~~~~~