fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. const int N = 2e5 + 1, M = 1e9 + 7;
  7. int fact[N], ifact[N];
  8.  
  9. int Pow(int a, int b) {
  10. int res = 1;
  11. while (b != 0) {
  12. if (b & 1)
  13. res = ((ll) res * a) % M;
  14. a = ((ll) a * a) % M;
  15. b >>= 1;
  16. }
  17. return res;
  18. }
  19.  
  20. inline int nCk(int n, int k) {
  21. if (k > n)
  22. return 0;
  23. return (((ll) fact[n] * ifact[k]) % M * ifact[n - k]) % M;
  24. }
  25.  
  26. inline int calcP(int n, int m) {
  27. if (m == 0 && n == 0)
  28. return 1;
  29. if (m == 0 || abs(n) > m || (abs(n) & 1) != (m & 1))
  30. return 0;
  31. return nCk(m, (m + n) >> 1);
  32. }
  33.  
  34. int main(int argc, char **argv) {
  35. fact[0] = ifact[0] = 1;
  36. for (int i = 1; i < N; ++i) {
  37. fact[i] = ((ll) fact[i - 1] * i) % M;
  38. ifact[i] = Pow(fact[i], M - 2);
  39. }
  40. int T;
  41. scanf("%d", &T);
  42. while (T-- != 0) {
  43. int n, m;
  44. scanf("%d%d", &n, &m);
  45. int p = calcP(n, m);
  46. int q = Pow(2, m);
  47. printf("%lld\n", ((ll) p * Pow(q, M - 2)) % M);
  48. }
  49. return 0;
  50. }
Success #stdin #stdout 0.03s 4708KB
stdin
3
0 0
1 1
-3 3
stdout
1
500000004
125000001