Advertisement
Morass

TEAM-SONGMAN

Sep 9th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using LINT = long long int;
  5. using PII = pair<int,int>;
  6.  
  7. #define PB push_back
  8. #define FI first
  9. #define SE second
  10. #define REP(i,n) for(int i=0;i<(n);++i)
  11. #define FOR(i, a, b) for(int i=(a);i<(b);++i)
  12.  
  13. LINT n,a,b,d;
  14.  
  15. LINT LEMOD = 1000000007;
  16.  
  17. LINT modinv(LINT num, LINT m){
  18.     LINT mat[2][3];
  19.     mat[0][0]=m;mat[0][1]=1;mat[0][2]=0;
  20.     mat[1][0]=num;mat[1][1]=0;mat[1][2]=1;
  21.  
  22.     while(mat[1][0]!=0){
  23.         LINT diff = mat[0][0]/mat[1][0];
  24.         mat[0][0] -= diff*mat[1][0];
  25.         mat[0][1] -= diff*mat[1][1];
  26.         mat[0][2] -= diff*mat[1][2];
  27.         swap(mat[0][0],mat[1][0]);
  28.         swap(mat[0][1],mat[1][1]);
  29.         swap(mat[0][2],mat[1][2]);
  30.     }
  31.     return (mat[0][2]+2*m)%m;
  32. }
  33.  
  34. LINT facts[1000007];
  35. LINT ifacts[1000007];
  36.  
  37. LINT combo(LINT n, LINT k){
  38.     return facts[n]*ifacts[n-k]%LEMOD*ifacts[k]%LEMOD;
  39. }
  40.  
  41. LINT fpow(LINT b, LINT e, LINT m){
  42.     LINT p = 1;
  43.     LINT ex = b;
  44.     while(e){
  45.         if(e&1)
  46.             p = p*ex%m;
  47.         ex = ex*ex%m;
  48.         e>>=1;
  49.     }
  50.     return p;
  51. }
  52.  
  53. bool process(){
  54.     cin>>n>>a>>b>>d;
  55.     if(!cin) return false;
  56.     cout<<combo(n,a)*fpow(combo(b,d),a,LEMOD)%LEMOD<<endl;
  57.     return true;
  58. }
  59.  
  60. int main() {
  61.     facts[0] = 1;
  62.     ifacts[0] = 1;
  63.  
  64.     FOR(i,1,1000007){
  65.         facts[i] = facts[i-1]*i%LEMOD;
  66.         ifacts[i]=modinv(facts[i],LEMOD);
  67.     }
  68.  
  69.  
  70.     while(process());
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement