fork download
  1. #include<iostream>
  2. using namespace std;
  3. #define mod 1000000007
  4. long long a,b,c;
  5. long long fact[300000],inv[300000],factinv[300000],power[300000];
  6. int ncr(int n,int r){
  7. if(n-r==0 && r==-1){return 1;}
  8. if(n-r<0 || r<0){return 0;}
  9. return 1LL*fact[n]*factinv[r]%mod*factinv[n-r]%mod;
  10. }
  11. void equip(){
  12. fact[0]=1;
  13. for(int i=1;i<300000;i++){
  14. fact[i]=(1LL*fact[i-1]*i)%mod;
  15. }
  16. inv[1]=1;
  17. for(int i=2;i<300000;i++){
  18. inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
  19. }
  20. factinv[0]=1;
  21. for(int i=1;i<300000;i++){
  22. factinv[i]=1LL*factinv[i-1]*inv[i]%mod;
  23. }
  24. power[0]=1;
  25. for(int i=1;i<300000;i++){
  26. power[i]=(1LL*power[i-1]*b)%mod;
  27. }
  28. }
  29. int main(){
  30. cin>>a>>b>>c;
  31. long long sum=0;equip();
  32. for(int i=0;i<a;i++){
  33. int C=c-1,N=C+i;
  34. sum+=(1LL*ncr(N,C)*power[a-1-i])%mod;
  35. sum%=mod;
  36. }
  37. cout<<sum<<endl;
  38. return 0;
  39. }
Success #stdin #stdout 0.06s 12832KB
stdin
4 3 2
stdout
58