Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define MOD 1000000007
- #define MX 100005
- ll bigmod(ll a, ll b) {
- ll res = 1;
- while (b) {
- if (b & 1)
- res = res * a % MOD;
- a = a * a % MOD;
- b >>= 1;
- }
- return res;
- }
- ll inv(ll a, ll b){ // a^-1 % b
- return 1<a ? b - inv(b%a,a)*b/a : 1; // credit : aitch (cf handle) for this one liner
- }
- ll fact[MX];
- ll modInv[MX];
- ll solve2(ll n, ll m){
- ll i, ans = 1;
- ans = ((m * fact[n]) % MOD * modInv[m+1]) % MOD;
- return ans;
- }
- int main() {
- ios::sync_with_stdio(false);
- #ifndef ONLINE_JUDGE
- // freopen("/home/nuwaisir/CP_Stuffs/Contests/CodeForces/div2_cf_round_#600/myin", "r", stdin);
- // freopen("/home/nuwaisir/CP_Stuffs/Contests/CodeForces/div2_cf_round_#600/myout", "w", stdout);
- #endif
- ll n, m, i;
- fact[0] = 1;
- for(i=1;i<MX;i++) fact[i] = (i * fact[i-1]) % MOD;
- for(i=1;i<MX;i++) modInv[i] = bigmod(i, MOD - 2);
- int t;
- cin >> t;
- //srand(time(0));
- while(t--){
- cin >> n >> m;
- //n = rand() % 100000 + 1;
- //m = n - 1 - (rand() % (n-1) + 1);
- cout << solve2(n,m) << "\n";
- //cout << n << " " << m << "\n";
- // if(solve(n,m) != solve2(n,m)){
- // cout << "uhum\n";
- // }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement