• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Nov 19th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <bits/stdc++.h>
2. using namespace std;
3. typedef long long ll;
4. #define MOD 1000000007
5. #define MX 100005
6.
7. ll bigmod(ll a, ll b) {
8.     ll res = 1;
9.     while (b) {
10.         if (b & 1)
11.             res = res * a % MOD;
12.         a = a * a % MOD;
13.         b >>= 1;
14.     }
15.     return res;
16. }
17.
18. ll inv(ll a, ll b){ // a^-1 % b
19.     return 1<a ? b - inv(b%a,a)*b/a : 1;   // credit :  aitch (cf handle) for this one liner
20. }
21.
22. ll fact[MX];
23. ll modInv[MX];
24.
25.
26. ll solve2(ll n, ll m){
27.     ll i, ans = 1;
28.     ans = ((m * fact[n]) % MOD * modInv[m+1]) % MOD;
29.     return ans;
30. }
31.
32.
33. int main() {
34.     ios::sync_with_stdio(false);
35. #ifndef ONLINE_JUDGE
36. //    freopen("/home/nuwaisir/CP_Stuffs/Contests/CodeForces/div2_cf_round_#600/myin", "r", stdin);
37. //    freopen("/home/nuwaisir/CP_Stuffs/Contests/CodeForces/div2_cf_round_#600/myout", "w", stdout);
38. #endif
39.     ll n, m, i;
40.     fact[0] = 1;
41.     for(i=1;i<MX;i++) fact[i] = (i * fact[i-1]) % MOD;
42.     for(i=1;i<MX;i++) modInv[i] = bigmod(i, MOD - 2);
43.     int t;
44.     cin >> t;
45.     //srand(time(0));
46.     while(t--){
47.         cin >> n >> m;
48.         //n = rand() % 100000 + 1;
49.         //m = n - 1 - (rand() % (n-1) + 1);
50.         cout << solve2(n,m) << "\n";
51.         //cout << n << " " << m << "\n";
52. //        if(solve(n,m) != solve2(n,m)){
53. //            cout << "uhum\n";
54. //        }
55.     }
56.
57.     return 0;
58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top