用 C# 代码提交 P3807 为何 CE?
namespace Luogu {
public class Program {
private const int maxn = 100001;
private static int t, n, m, p;
private static long[] a = new long[maxn], b = new long[maxn];
public static void Main() {
t = int.Parse(Console.ReadLine());
while (t-- != 0) {
string[] res = Console.ReadLine().Split(" ");
n = int.Parse(res[0]);
m = int.Parse(res[1]);
p = int.Parse(res[2]);
a[0] = a[1] = b[0] = b[1] = 1;
for (int i = 2; i <= n + m; i++) {
b[i] = b[i - 1] * i % p;
}
for (int i = 2; i <= n + m; i++) {
a[i] = (p - p / i) * a[p % i] % p;
}
for (int i = 2; i <= n + m; i++) {
a[i] = a[i - 1] * a[i] % p;
}
Console.WriteLine(Lucas(n + m, m));
}
}
private static long Lucas(int x, int y) {
if (x < y) {
return 0;
}
else if (x < p) {
return b[x] * a[y] * a[x - y] % p;
} else {
return Lucas(x / p, y / p) * Lucas(x % p, y % p) % p;
}
}
}
}