白兔的式子html
\(\binom{n-1}{m-1}a^{n-m}b^{m-1}\),發現數據是1e5,因此用階乘求,至於有理數取餘能夠看這篇題解c++
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 1e5 + 20; const int mod = 998244353; int t, n, m, a, b; int jc[N]; template<class T>inline void read(T &x) { x = 0; int f = 0; char ch = getchar(); while (!isdigit(ch)) f |= (ch == '-'), ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); x = f ? -x : x; return; } void init(int n = 100010) { jc[0] = 1; for (int i = 1; i <= n; ++i) jc[i] = (jc[i - 1] * i) % mod; } int qpow(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod, b >>= 1; } return ans; } int C(int n, int m) { return (jc[n] * qpow((jc[n - m] * jc[m]) % mod, mod - 2)) % mod; } signed main() { init(); read(t); while (t--) { read(a), read(b), read(n), read(m); cout << ((C(n - 1, m - 1) * qpow(a, n - m)) % mod * qpow(b, m - 1)) % mod << '\n'; } }