Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- #include<vector>
- /* This function calculates (a^b)%MOD */
- long long pow(int a, int b, int MOD)
- {
- long long x=1,y=a;
- while(b > 0)
- {
- if(b%2 == 1)
- {
- x=(x*y);
- if(x>MOD) x%=MOD;
- }
- y = (y*y);
- if(y>MOD) y%=MOD;
- b /= 2;
- }
- return x;
- }
- /* Modular Multiplicative Inverse
- Using Euler's Theorem
- a^(phi(m)) = 1 (mod m)
- a^(-1) = a^(m-2) (mod m) */
- long long InverseEuler(int n, int MOD)
- {
- return pow(n,MOD-2,MOD);
- }
- long long C(int n, int r, int MOD)
- {
- if(r<=0||r>n) return 1;
- vector<long long> f(n,1);
- for (int i=2; i<=n;i++)
- f[i]= (f[i-1]*i) % MOD;
- return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
- }
- main()
- {
- long long n=1,k=1,l,tmp;
- while(n!=0&&k!=0)
- {
- cin>>n>>k;
- l=k+1;
- if(l%2==0)
- {
- tmp= 2* pow( C(n-2,(l/2)-1,1000000007),2,1000000007);
- }
- else
- tmp=2*C(n-2,(l-1)/2,1000000007)*C(n-2,(l-3)/2,1000000007);
- cout<<tmp<<"\n";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment