fork download
  1. #include<stdio.h>
  2. using lld = long long int;
  3. // solution from https://h...content-available-to-author-only...n.hr/studenti2020/
  4. // See https://e...content-available-to-author-only...a.org/wiki/Fuss%E2%80%93Catalan_number
  5.  
  6. constexpr lld M = 1'000'000'007;
  7. int n,m;
  8. lld expp(lld p,lld q){
  9. lld r=1;
  10. lld z=p;
  11. while(q){
  12. if(q&1)r=r*z%M;
  13. z=z*z%M;
  14. q>>=1;
  15. }
  16. return r;
  17. }
  18. int main(){
  19. scanf("%d%d",&n,&m);
  20. // nm C n / (nm-n+1)
  21. lld p=(lld)n*m;
  22. lld r=1;
  23. lld f=n;
  24. for(int i=1;i<n;i++){
  25. r=r*(p--)%M;
  26. f=f*i%M;
  27. }
  28. r=r*expp(f,M-2)%M;
  29. printf("%lld",r);
  30. }
Success #stdin #stdout 0.01s 5308KB
stdin
3 4
stdout
22