| | |
1
| | |
| | |
1
|
2
| |
2
| | |
1
| | |
| | |
1
|
2
|
3
|
3
| | |
1
|
2
| |
2
| | |
1
|
3
| |
解题代码:
#include <iostream>
const int N = 1000000; const int MOD = 1000000007; long long p[N + N + 1]; long long rev[N + N + 1]; void ext_gcd(long long x, long long y, long long *a, long long *b) { if (y == 0) { *a = 1; *b = 0; } else { ext_gcd(y, x % y, a, b); long long t = *a; *a = *b; *b = t - *b * (x / y); } } void precompute() { p[0] = 1; for (int i = 1; i <= N + N; ++i) { p[/color][i][color=#000000] = p[i - 1] * i % MOD; long long a; long long b; ext_gcd(p[/color][i][color=#000000], MOD, &a, &b); rev[/color][i][color=#000000] = (a % MOD + MOD) % MOD; } } int main(int argc, char *argv[]) { precompute(); int T; std::cin >> T; for (int c = 1; c <= T; ++c) { int n; std::cin >> n; fprintf(stdout, "Case #%d:\n", c); long long res = p[n + n] * rev[n + 1] % MOD * rev[n] % MOD; fprintf(stdout, "%d\n", static_cast<int>(res)); } return 0; } /* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */