-
Notifications
You must be signed in to change notification settings - Fork 3
/
H.cpp
49 lines (40 loc) · 1.08 KB
/
H.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// LUOGU_RID: 160328690
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define eb emplace_back
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int N = 2e6+5;
const int Mod = 998244353;
int n, m;
ll inv[N], fac[N], ifac[N], ans;
inline void Add(ll &a, ll b) { a += b; if (a >= Mod) a -= Mod; }
inline ll qpow(int a, int b) {
ll base = a, ans = 1;
while (b) {
if (b & 1) ans = ans * base % Mod;
base = base * base % Mod;
b >>= 1;
}
return ans;
}
ll C(ll n, ll m) { return m > n ? 0 : fac[n] * ifac[m] % Mod * ifac[n - m] % Mod; }
int main() {
scanf("%d%d", &n, &m);
fac[0] = 1;
for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % Mod;
ifac[N - 1] = qpow(fac[N - 1], Mod - 2);
for (int i = N - 1; i; i--) {
ifac[i - 1] = ifac[i] * i % Mod;
inv[i] = ifac[i] * fac[i - 1] % Mod;
}
for (int i = 1; i <= n; i++) {
ll t = C(n, i) * (1 + m * inv[i] % Mod) % Mod;
Add(ans, i & 1 ? t : Mod - t);
}
ans = ans * (n + m + 1) % Mod * inv[m + 1] % Mod;
printf("%lld", ans);
return 0;
}