fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define el '\n'
  4. #define fi first
  5. #define sec second
  6. #define pb push_back
  7. #define ll long long
  8. #define sz(v) (int)(v).size()
  9. #define all(v) (v).begin(),(v).end()
  10. #define FOR(i, a, b) for(int i = (a), _b = b; i <= _b; i++)
  11. #define REP(i, a, b) for(int i = (a), _b = b; i >= _b; i--)
  12.  
  13. using namespace std;
  14.  
  15. const int MAX_N = 1e7;
  16. const int MOD = 1e9 + 7;
  17.  
  18. int fact[2 * MAX_N + 5], invfact[2 * MAX_N + 5];
  19. int n, m;
  20.  
  21. void Input(){
  22. cin >> n >> m;
  23. }
  24.  
  25. ll bin_pow(ll a, int b){
  26. ll res = 1;
  27. while(b){
  28. if(b & 1) res = (res * a) % MOD;
  29. a = (a * a) % MOD;
  30. b /= 2;
  31. }
  32. return res;
  33. }
  34.  
  35. ll C(int k, int n){
  36. return 1LL * fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
  37. }
  38.  
  39. void Solve(){
  40.  
  41. fact[0] = 1;
  42. FOR(i, 1, n + m) fact[i] = (1LL * fact[i - 1] * i) % MOD;
  43.  
  44.  
  45. invfact[n + m] = bin_pow(fact[n + m], MOD - 2);
  46. REP(i, n + m - 1, 0) invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
  47.  
  48. ll ans = 0;
  49. FOR(k, 0, min(n, m)){
  50. ans = (ans + (1LL * C(n - k, n + m - k) * C(m - k, m)) % MOD) % MOD;
  51. }
  52.  
  53. cout << ans;
  54. }
  55.  
  56. int main(){
  57. ios_base::sync_with_stdio(0);
  58. cin.tie(0);
  59.  
  60. Input();
  61. Solve();
  62. }
  63.  
Success #stdin #stdout 0.01s 5704KB
stdin
Standard input is empty
stdout
1