fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. template<const int mod>
  26. struct mint {
  27. int val;
  28. constexpr mint(long long x = 0) : val((x % mod + mod) % mod) {}
  29. explicit operator int() const { return val; }
  30. mint& operator+=(const mint &b) { val += b.val; val -= mod * (val >= mod); return *this; }
  31. mint& operator-=(const mint &b) { val -= b.val; val += mod * (val < 0); return *this; }
  32. mint& operator*=(const mint &b) { val = 1ll * val * b.val % mod; return *this; }
  33. mint& operator/=(const mint &b) { return *this *= b.inv(); }
  34. mint inv() const { int x = 1, y = 0, t; for(int a=val, b=mod; b; swap(a, b), swap(x, y)) t = a/b, a -= t * b, x -= t * y; return mint(x); }
  35. mint power(int b) const { mint a = *this, res(1); for(; b; a *= a, b /= 2) if(b & 1) res *= a; return res; }
  36. mint operator-() const { return val == 0 ? 0 : mod - val; }
  37. mint& operator++() { val = val == mod - 1 ? 0 : val + 1; return *this; }
  38. mint& operator--() { val = val == 0 ? mod - 1 : val - 1; return *this; }
  39. mint operator++(int32_t) { mint before = *this; ++*this; return before; }
  40. mint operator--(int32_t) { mint before = *this; --*this; return before; }
  41. friend mint operator+(const mint &a, const mint &b) {return mint(a) += b;}
  42. friend mint operator-(const mint &a, const mint &b) {return mint(a) -= b;}
  43. friend mint operator*(const mint &a, const mint &b) {return mint(a) *= b;}
  44. friend mint operator/(const mint &a, const mint &b) {return mint(a) /= b;}
  45. friend bool operator==(const mint &a, const mint &b) {return a.val == b.val;}
  46. friend bool operator!=(const mint &a, const mint &b) {return a.val != b.val;}
  47. friend bool operator<(const mint &a, const mint &b) {return a.val < b.val;}
  48. friend istream& operator>>(istream &in, mint &a) {return in >> a.val;}
  49. friend ostream& operator<<(ostream &os, const mint &a) {return os << a.val;}
  50. };
  51. using Mint = mint<M>;
  52.  
  53. namespace comb {
  54. int n(0);
  55. vector<Mint> _fac{1}, _invfac{1}, _inv{0};
  56. void init(int m) {
  57. m = min (m, M - 1);
  58. if (m <= n) return;
  59. _fac.resize(m + 1); _invfac.resize(m + 1); _inv.resize(m + 1);
  60. for (int i = n + 1; i <= m; i++) _fac[i] = _fac[i - 1] * i;
  61. _invfac[m] = _fac[m].inv();
  62. for (int i = m; i > n; i--) _invfac[i - 1] = _invfac[i] * i, _inv[i] = _invfac[i] * _fac[i - 1];
  63. n = m;
  64. }
  65. Mint fac(int m) { if (m > n) init(2 * m); return _fac[m]; }
  66. Mint invfac(int m) { if (m > n) init(2 * m); return _invfac[m]; }
  67. Mint inv(int m) { if (m > n) init(2 * m); return _inv[m]; }
  68. Mint nCr(int n, int r) { if (n < r || r < 0) return 0; return fac(n) * invfac(r) * invfac(n - r); }
  69. }
  70. using comb::fac, comb::invfac, comb::inv, comb::nCr;
  71.  
  72.  
  73.  
  74.  
  75. //_ ***************************** START Below *******************************
  76.  
  77.  
  78. //* Remember to typecast before using nCr
  79.  
  80. int consistency(int n, int r){
  81.  
  82. int ans = (int)nCr(n, r);
  83.  
  84. return ans;
  85.  
  86. // return (int)nCr(n, r);
  87.  
  88. }
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. void solve() {
  96.  
  97. int n, r;
  98. cin>> n >> r;
  99.  
  100. cout << consistency(n, r) << endl;
  101.  
  102.  
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109. int32_t main() {
  110. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  111.  
  112. int t = 1;
  113. cin >> t;
  114. while (t--) {
  115. solve();
  116. }
  117.  
  118. return 0;
  119. }
Success #stdin #stdout 0.01s 5284KB
stdin
4
5 2
3 5
10 2
4 3
stdout
10
0
45
4