it is most probabily because of the binomial function you are using,
admit you only copy pasted the functions and didn’t changed anything in them.
you need to append your binomial funtion to make it work with mod, here is code for that.
incase you don't know
To perform modular divisions, it is not as simple as modular multiplications.
you need to actually multiply the numerator with modular multiplicative inverse of the denominator.
a / b ==> (a mod m) * (modular inverse b) % mod
for a prime modulo m, modular inverse a number is
modular multiplicative inverse of b is
b raised to power (m - 2) mod m
for more info visit https://cp-algorithms.com/algebra/module-inverse.html
Code
long long mod = 998244353;
long long power (long long a, long long b = mod - 2) {
if (a == 0) return 0;
long long ret = 1;
while (b) {
if (b & 1) (ret *= a) %= mod;
b = b>>1;
(a *= a) %= mod;
}
return ret;
}
// Returns value of Binomial
// Coefficient C(n, k)
lli binomialCoeff(lli n, lli k)
{
lli res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k)
k = n - k;
// Calculate value of
// [n * (n-1) *---* (n-k+1)] /
// [k * (k-1) *----* 1]
for (lli i = 0; i < k; ++i) {
res *= (n - i);
res %= mod;
res *= power(i + 1);
res %= mod;
}
return res;
}