fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. long long numerator[1002002];
  5. long long denomerator[1002002];
  6. long long a,b,n,MOD;
  7.  
  8. long long power(long long b,long long p) {
  9. if(p == 0)
  10. return 1;
  11. long long ans = power(b,p/2);
  12. ans = (ans*ans) % MOD;
  13. if(p % 2)
  14. return (ans * b) % MOD;
  15. return ans;
  16. }
  17.  
  18. long long solve(long long num,long long den) {
  19. return (num * power(den,MOD-2)) % MOD;
  20. }
  21.  
  22. int main()
  23. {
  24. cin>>a>>b>>n>>MOD;
  25. long long facA = a; //represents (a+k)! / (a-b) !
  26. for(long long i = a-1;i>a-b;i--)
  27. facA = (facA * i) % MOD;
  28. long long facB = 1;
  29. for(long long i = 2;i<=b;i++)
  30. facB*=i;
  31. //numerator[i] = (a+i)! / (a-b)!
  32. //denominator[i] = (b+i)!
  33. numerator[0] = facA;
  34. denomerator[0] = facB;
  35. long long ans = solve(facA,facB);
  36. for(long long i = 1;i<=n;i++) {
  37. numerator[i] = (numerator[i-1] * (a+i)) % MOD;
  38. denomerator[i] = (denomerator[i-1] * (b+i)) % MOD;
  39. ans = max(ans,solve(numerator[i],denomerator[i]));
  40. }
  41. cout<<ans;
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 30896KB
stdin
5 3 5 1037
stdout
202