fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long p=1000000007;
  4. long long fmod(long long x){
  5.  
  6. if(x==1)return 1;
  7. return ((x%p)*fmod(x-1))%p;
  8. }
  9. ///using fermats little theorem
  10. long long mmi(long long x){
  11. long long y = p-2;
  12. long long result = 1;
  13. while(y){
  14. if(y&1)result = (result*x)%p;
  15. x = (x*x)%p;
  16. y>>=1;
  17. }
  18. return result;
  19. }
  20.  
  21. int main(){
  22. int t;
  23. cin>>t;
  24. while(t--){
  25. long long n,m;
  26. cin>>n>>m;
  27. printf("%lld\n", ((fmod(m+n-2)*mmi(((fmod(m-1)%p)*(fmod(n-1)%p))%p))%p));
  28. }
  29.  
  30. }
  31.  
Success #stdin #stdout 0.47s 72064KB
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