Advertisement
limimage

Untitled

Mar 9th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define endl "\n"
  4. using namespace std;
  5. using ll = long long;
  6. using ld = long double;
  7. using pii = pair<int, int>;
  8.  
  9. constexpr int N = 2e5 + 5;
  10. constexpr int mod = 998244353;
  11.  
  12. int n, m;
  13. int ans = 0;
  14. int fact[N], rfact[N];
  15.  
  16. int sum(ll a, ll b) {
  17. return (a + b) % mod;
  18. }
  19.  
  20. int mul(ll a, ll b) {
  21. return (a * b) % mod;
  22. }
  23.  
  24. int binpow(int v, int deg) {
  25. int cur = 1;
  26. while(deg) {
  27. if (deg & 1)
  28. cur = mul(cur, v);
  29. v = mul(v, v);
  30. deg >>= 1;
  31. }
  32. return cur;
  33. }
  34.  
  35. int C(int i, int j) {
  36. return mul(fact[i], mul(rfact[i - j], rfact[j]));
  37. }
  38.  
  39. void Solve() {
  40. cin >> n >> m;
  41. fact[0] = 1;
  42. for (int i = 1; i <= m; i++)
  43. fact[i] = mul(fact[i - 1], i);
  44. rfact[m] = binpow(fact[m], mod - 2);
  45. for (int i = m - 1; i >= 0; i--)
  46. rfact[i] = mul(rfact[i + 1], i + 1);
  47. for (int i = 2; i < n; i++) {
  48. for (int j = max(i, n - 1); j <= m; j++)
  49. ans = sum(ans, mul(C(j - 1, i - 1), C(j - i, n - i - 1)));
  50. }
  51. cout << ans;
  52. }
  53.  
  54. int main() {
  55. ios::sync_with_stdio(false);
  56. cin.tie(nullptr);
  57. cout.tie(nullptr);
  58. //auto start = chrono::high_resolution_clock::now();
  59. Solve();
  60. //auto end = chrono::high_resolution_clock::now();
  61. //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement