|
| 1 | +#include<bits/stdc++.h> |
| 2 | + |
| 3 | +using namespace std; |
| 4 | + |
| 5 | +#define ms(x,v) memset(x,(v), sizeof(x)) |
| 6 | +#define msn(x,v,n) memset(x,(v),sizeof(x[0]) * n) |
| 7 | +#define INF 0x3f3f3f3f |
| 8 | +#define random(a,b) (rand() % ((b) -(a)) +(a)) |
| 9 | + |
| 10 | +typedef long long LL; |
| 11 | +typedef pair<int,int> PII; |
| 12 | + |
| 13 | +const double EPS = 2e-8; |
| 14 | +const LL MOD = 1e9+7; |
| 15 | +const int MAX_FAC = 1e5+10; |
| 16 | +LL fac[MAX_FAC * 2]; |
| 17 | + |
| 18 | +void init(){ |
| 19 | + fac[0] =1; |
| 20 | + for(int i=1 ; i < MAX_FAC * 2 ; ++i) |
| 21 | + fac[i] = fac[i-1] * i % MOD; |
| 22 | +} |
| 23 | + |
| 24 | +LL power_mod(LL x,LL n,LL mod){ |
| 25 | + LL ret = 1; |
| 26 | + while (n) |
| 27 | + { |
| 28 | + if(n&1) ret = x * ret % mod; |
| 29 | + x = x * x % mod; |
| 30 | + n >>= 1; |
| 31 | + } |
| 32 | + return ret; |
| 33 | +} |
| 34 | + |
| 35 | +void solve(){ |
| 36 | + int N,M; |
| 37 | + cin >> N >> M; |
| 38 | + |
| 39 | + LL ans =0; |
| 40 | + LL power2 = 1; |
| 41 | + for(int k=0; k<=M; ++k){ |
| 42 | + |
| 43 | + LL cur_ans = power2; |
| 44 | + power2 = power2 *2 % MOD; |
| 45 | + cur_ans = cur_ans * fac[M] % MOD * fac[2*N - k] % MOD; |
| 46 | + cur_ans = cur_ans * power_mod(fac[k] * fac[M-k]% MOD,MOD -2 ,MOD) % MOD; |
| 47 | + |
| 48 | + ans += k&1 ? MOD - cur_ans : cur_ans; |
| 49 | + ans %= MOD; |
| 50 | + } |
| 51 | + |
| 52 | + cout << " "<<ans; |
| 53 | +} |
| 54 | + |
| 55 | +int main(int argc, char const *argv[]) |
| 56 | +{ |
| 57 | + |
| 58 | + ios :: sync_with_stdio(0); |
| 59 | + cin.tie(0); |
| 60 | + // cout.tie(0); |
| 61 | + std::cout.precision(8); |
| 62 | + std::cout.setf( std::ios::fixed, std:: ios::floatfield ); |
| 63 | + |
| 64 | + init(); |
| 65 | + |
| 66 | + |
| 67 | + int T; |
| 68 | + cin >> T; |
| 69 | + |
| 70 | + for(int kase =1; kase <= T ; ++kase) |
| 71 | + { |
| 72 | + cout << "Case #"<<kase << ":"; |
| 73 | + |
| 74 | + solve(); |
| 75 | + cout << '\n'; |
| 76 | + } |
| 77 | + |
| 78 | + return 0; |
| 79 | +} |
0 commit comments