ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#164574 | #2908. count | larryzhong | 100 | 237ms | 1252kb | C++11 | 1.7kb | 2022-11-05 09:08:37 | 2022-11-05 13:00:59 |
answer
#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
template <class T> T qp(T a, int b) {
T c = 1;
for (; b; b /= 2, a *= a) {
if (b % 2) c *= a;
}
return c;
}
struct mint {
int x;
mint(int _x = 0) : x(_x % P) { x < 0 ? x += P : 0; }
int val() const { return x; }
mint operator - () const {
return !x ? 0 : P - x;
}
mint inv() const {
assert(x != 0);
return qp(*this, P - 2);
}
mint &operator += (const mint &rhs) {
x += rhs.x - P, x += x >> 31 & P;
return *this;
}
mint &operator -= (const mint &rhs) {
x -= rhs.x, x += x >> 31 & P;
return *this;
}
mint &operator *= (const mint &rhs) {
x = (long long)x * rhs.x % P;
return *this;
}
mint &operator /= (const mint &rhs) {
return *this *= rhs.inv();
}
friend mint operator + (const mint &lhs, const mint &rhs) {
mint res = lhs;
return res += rhs, res;
}
friend mint operator - (const mint &lhs, const mint &rhs) {
mint res = lhs;
return res -= rhs, res;
}
friend mint operator * (const mint &lhs, const mint &rhs) {
mint res = lhs;
return res *= rhs, res;
}
friend mint operator / (const mint &lhs, const mint &rhs) {
mint res = lhs;
return res /= rhs, res;
}
friend ostream &operator << (ostream &os, const mint &a) {
return os << a.val();
}
};
void solve() {
int n, m;
cin >> n >> m;
auto binom = [&](int x, int y) {
mint ans = 1;
for (int i = 1; i <= y; i++) {
ans *= x - i + 1;
ans /= i;
}
return ans;
};
mint ans = binom(n + m - 2, n - 1);
ans *= mint(n) * m - 1;
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 20
Accepted
time: 0ms
memory: 1252kb
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: 0ms
memory: 1252kb
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: 72ms
memory: 1252kb
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: 64ms
memory: 1252kb
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: 101ms
memory: 1248kb
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