UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#164754#2908. countty10014ms2716kbC++111.8kb2022-11-05 17:34:202022-11-05 17:34:21

answer


#ifdef TY
#include "/Users/ty/Desktop/code/ty.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;
namespace IO
{
  static int Len = 0, _t;
  char out[1 << 25]; // 32MB
  template <typename T>
  void read(T &x)
  {
    char ch = getchar();
    x = 0, _t = 0;
    while (ch < '0' || ch > '9')
      _t |= ch == '-', ch = getchar();
    while (ch >= '0' && ch <= '9')
      x = x * 10 + (ch ^ 48), ch = getchar();
    x = _t ? -x : x;
  }
  template <typename T, typename... Args>
  void read(T &x, Args &...args) { read(x), read(args...); }
  void putc(char ch) { out[Len++] = ch; }
  template <typename T>
  void write(T x)
  {
    if (x < 0)
      putc('-'), x = -x;
    if (x > 9)
      write(x / 10);
    out[Len++] = x % 10 + 48;
  }
  void flush() { fwrite(out, 1, Len, stdout), Len = 0; }
}
using namespace IO;
#define mod 1000000007
typedef unsigned long long ull;
typedef long long ll;
typedef __int128_t LL;
#define N 200010
#define l(x) (x & (-x))
#define INF 0x3f3f3f3f
int t, n, m, fac[200010] = {1}, inv[200010];
int qpow(int a, int b, int p)
{
  int res = 1;
  for (int t = a % p; b; b >>= 1)
  {
    if (b & 1)
      res = 1ll * res * t % p;
    t = 1ll * t * t % p;
  }
  return res;
}
int main()
{
#ifdef TY
  freopen("/Users/ty/Desktop/code/data.in", "r", stdin);
  // freopen("my.out", "w", stdout);
#endif
  for (int i = 1; i <= 200000; i++)
    fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[200000] = qpow(fac[200000], mod - 2, mod);
  for (int i = 199999; i >= 0; i--)
    inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  read(t);
  for (int i = 1; i <= t; i++)
  {
    read(n), read(m);
    printf("%lld\n", (1ll * n * m % mod - 1) * (1ll * fac[n + m - 2] * inv[n - 1] % mod * inv[m - 1] % mod) % mod);
  }
  return 0;
}

Details

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

Test #1:

score: 20
Accepted
time: 4ms
memory: 2712kb

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: 4ms
memory: 2712kb

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: 2712kb

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: 2ms
memory: 2716kb

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: 4ms
memory: 2712kb

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