Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using LINT = long long int;
- using PII = pair<int,int>;
- #define PB push_back
- #define FI first
- #define SE second
- #define REP(i,n) for(int i=0;i<(n);++i)
- #define FOR(i, a, b) for(int i=(a);i<(b);++i)
- LINT n,a,b,d;
- LINT LEMOD = 1000000007;
- LINT modinv(LINT num, LINT m){
- LINT mat[2][3];
- mat[0][0]=m;mat[0][1]=1;mat[0][2]=0;
- mat[1][0]=num;mat[1][1]=0;mat[1][2]=1;
- while(mat[1][0]!=0){
- LINT diff = mat[0][0]/mat[1][0];
- mat[0][0] -= diff*mat[1][0];
- mat[0][1] -= diff*mat[1][1];
- mat[0][2] -= diff*mat[1][2];
- swap(mat[0][0],mat[1][0]);
- swap(mat[0][1],mat[1][1]);
- swap(mat[0][2],mat[1][2]);
- }
- return (mat[0][2]+2*m)%m;
- }
- LINT facts[1000007];
- LINT ifacts[1000007];
- LINT combo(LINT n, LINT k){
- return facts[n]*ifacts[n-k]%LEMOD*ifacts[k]%LEMOD;
- }
- LINT fpow(LINT b, LINT e, LINT m){
- LINT p = 1;
- LINT ex = b;
- while(e){
- if(e&1)
- p = p*ex%m;
- ex = ex*ex%m;
- e>>=1;
- }
- return p;
- }
- bool process(){
- cin>>n>>a>>b>>d;
- if(!cin) return false;
- cout<<combo(n,a)*fpow(combo(b,d),a,LEMOD)%LEMOD<<endl;
- return true;
- }
- int main() {
- facts[0] = 1;
- ifacts[0] = 1;
- FOR(i,1,1000007){
- facts[i] = facts[i-1]*i%LEMOD;
- ifacts[i]=modinv(facts[i],LEMOD);
- }
- while(process());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement