UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#164581#2908. countwdssean1009ms2832kbC++112.5kb2022-11-05 09:23:192022-11-05 13:01:11

answer

/*
* @Author: ftt2333
* @Email: [email protected]
* @Last Modified time: 2022-11-05 09:23:02
*/

#include <bits/stdc++.h>
using namespace std;
#define qin cin
#define qout cout
#define off ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fin(s) freopen(s, "r", stdin)
#define fout(s) freopen(s, "w", stdout)
#define fio(s) fin(s".in"), fout(s".out")
using ll = long long; using ull = uint64_t;
using lll = __int128; using ulll = __uint128_t;
using db = double; using ldb = long double;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using vi = vector<int>; using vl = vector<ll>;
using uchar = unsigned char; using uint = unsigned int;
template<class T> using uid = uniform_int_distribution<T>;
template<class T> using urd = uniform_real_distribution<T>;
#define rep(i, a, b) for(auto i = (a); i <= (b); i++)
#define per(i, a, b) for(auto i = (a); i >= (b); i--)
#define go(i, h, e, x) for(int i = h[x]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define szof(a) ((int)(a).size())
#define mem(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))

mt19937 rnd(random_device{}());
const ll mod = 1e9 + 7;
const int N = 2e5 + 10;

ll gcd(ll a, ll b) { return a? gcd(b % a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
void exgcd(ll a, ll b, ll &x, ll &y) {
  if(!b) { x = 1, y = 0; return; }
  exgcd(b, a % b, y, x); y -= a / b * x;
}
ll inv(ll a, ll p) { ll x, y; exgcd(a, p, x, y); return (x % p + p) % p; }
ll inv(ll x) { return inv(x, mod); }
ll qmul(ll x, ll y, ll p) { return ((lll)x * y) % p; }
ll qmul(ll x, ll y) { return qmul(x, y, mod); }
ll qpow(ll x, ll y, ll p) {
  ll r = 1;
  for(; y; y >>= 1, x = qmul(x, x, p))
    if(y & 1) r = qmul(r, x, p);
  return r;
}
ll qpow(ll x, ll y) { return qpow(x, y, mod); }

int fact[N], ifact[N];
int binom(int n, int m) {
  if(m > n || m < 0 || n < 0) return 0;
  return 1ll * fact[n] * ifact[m] % mod * ifact[n - m] % mod;
}
void init() {
  fact[0] = 1;
  rep(i, 1, N - 1) fact[i] = 1ll * fact[i - 1] * i % mod;
  ifact[N - 1] = inv(fact[N - 1]);
  per(i, N - 1, 1) ifact[i - 1] = 1ll * ifact[i] * i % mod;
}

void solve() {
  int n, m;
  qin >> n >> m;
  int e = binom(n + m - 2, n - 1);
  int e1 = 1ll * (m - 1) * (n + 1) % mod;
  int e2 = 1ll * (n - 1) * (m + 1) % mod;
  int ans = 1ll * e * (e1 + e2) % mod * inv(2) % mod;
  qout << ans << '\n';
}

int main() {
  init();
  int t; qin >> t;
  for(; t--; ) solve();
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 20
Accepted
time: 0ms
memory: 2832kb

input:

10
1 1
2000 1997
117 1647
392 452
959 1883
1046 1627
1398 1124
1372 306
1799 1007
111 1765

output:

0
57631948
737963048
807538931
137760374
398194748
77480423
174938019
583393917
445670336

result:

ok 10 lines

Test #2:

score: 20
Accepted
time: 3ms
memory: 2828kb

input:

10
1 1
2000 1997
1218 1479
350 1244
784 1715
999 92
396 1393
1726 1511
624 756
900 317

output:

0
57631948
610566455
356523655
593949258
665757514
349394180
73375269
50652564
663822508

result:

ok 10 lines

Test #3:

score: 20
Accepted
time: 0ms
memory: 2832kb

input:

10
1 1
100000 99997
36934 50467
5497 37576
83775 15544
23817 68917
33052 49207
59924 39340
2708 2614...

output:

0
73866797
788834869
539491921
582239610
497376436
343937059
324406513
13225836
35059446

result:

ok 10 lines

Test #4:

score: 20
Accepted
time: 3ms
memory: 2828kb

input:

10
1 1
100000 99997
6792 14252
90281 65716
46434 67120
18977 30384
16191 33996
3425 10433
31783 4263...

output:

0
73866797
609230597
213203975
638117274
527713366
525065128
867713025
174019248
375031322

result:

ok 10 lines

Test #5:

score: 20
Accepted
time: 3ms
memory: 2828kb

input:

10
1 1
100000 99994
47270 99792
93093 92620
88764 20724
48143 99711
33293 89038
2816 16811
97638 670...

output:

0
796648553
5720713
279796657
802039459
22848874
23038351
610731858
629891152
812026839

result:

ok 10 lines