Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- ll mod=pow(10,9) +7;
- ll modexp(ll x,ll y)
- {
- ll res=1;
- while(y>0)
- {
- if(y%2==1) res=(res*x)%mod;
- y=y/2;
- x=(x*x)%mod;
- }
- return res;
- }
- ll modinv(ll x)
- {
- return (modexp(x,mod-2)+mod)%mod;
- }
- //O(k)
- ll comb(ll n, ll k)
- {
- ll res = 1;
- // Since C(n, k) = C(n, n-k)
- if ( k > n - k )
- k = n - k;
- // Calculate value of
- // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
- ll den=1;
- for (ll i = 0; i < k; ++i)
- {
- res = (res*(n - i))%mod;
- den = (den*(i+1))%mod;
- }
- res=(res*modinv(den))%mod;
- return res;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0); cout.tie(0);
- int t; cin>>t;
- while(t--)
- {
- ll n,k; cin>>n>>k;
- ll nCk=comb(n,k);
- ll ans = (nCk*modexp(2,k))%mod;
- cout<<ans<<endl;
- }
- }
Add Comment
Please, Sign In to add comment