提交时间:2022-08-08 11:31:41
运行 ID: 54933
#include <bits/stdc++.h> using namespace std; const int MXV = 10000001; const int DVS = 998244353; int T, M, N, fac[MXV + 5], inv[MXV + 5], facinv[MXV + 5], ans; int read() { int x(0); char c(getchar()); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); return x; } void write(int x) { if (x >= 10) write(x / 10); putchar((x % 10) | 48); } int main() { // freopen("line.in", "r", stdin); // freopen("line.out", "w", stdout); inv[1] = fac[0] = fac[1] = facinv[0] = facinv[1] = 1; for (int i(2); i <= MXV; ++i) { inv[i] = inv[DVS % i] * 1LL * (DVS - DVS / i) % DVS; fac[i] = fac[i - 1] * 1LL * i % DVS; facinv[i] = facinv[i - 1] * 1LL * inv[i] % DVS; } T = read(); while (T--) { M = read(); N = read(); if (N + 1 < M) { putchar(48); putchar(10); continue; } int ans(fac[N] * 1LL * fac[N + 1] % DVS); ans = ans * 1LL * facinv[N - M + 1] % DVS; write(ans); putchar(10); } // cout << clock() / 1000.0 << endl; return 0; }