fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int k = 1000000007;
  5.  
  6. long long f(long long a)
  7. {
  8. if(a<2)
  9. return 1;
  10. else
  11. return (a*f(a-1))%k;
  12. }
  13.  
  14. long long modpow(long long base, long long exp, long long modulus)
  15. {
  16. base %= modulus;
  17. long long result = 1;
  18.  
  19. while(exp > 0)
  20. {
  21. if(exp & 1)
  22. result = (result * base) % modulus;
  23.  
  24. base = (base * base) % modulus;
  25. exp >>= 1;
  26. }
  27.  
  28. return result;
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34. int t,m,n;
  35. cin >> t;
  36.  
  37. while(t--)
  38. {
  39. cin >> m >> n;
  40.  
  41.  
  42. long long temp = (f(n-1)%k*f(m-1)%k)%k;
  43. temp = modpow(temp,k-2,k); //(f(n)*f(m-1))^(10000000007-2)
  44.  
  45. long long result = (f(n+m-2)%k*temp%k)%k;
  46.  
  47. cout << result << endl;
  48. }
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0.29s 43592KB
stdin
9
524645 379018
934126 888771
877255 187002
794376 704320
515429 925706
744641 544701
500831 147443
134241 544167
466755 263186
stdout
470983035
360813896
984191444
843862199
35130564
903590134
877746074
601662583
684121266