Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include<iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#define maxn 10010using namespace std;typedef long long LL;int n, a[maxn], perm[5], fact[maxn], inv[maxn], C[maxn];LL Power(LL p, LL n, LL mod){LL ans = 1;for(; n; n >>= 1, p = p * p % mod)if (n & 1)ans = ans * p % mod;return ans;}int main(){int n, p, T;scanf("%d %d", &T, &p);fact[0] = inv[0] = 1;for (int i = 1; i <= 10000; ++i){fact[i] = (LL)fact[i - 1] * i % p;inv[i] = Power(fact[i], p - 2, p);}for (int i = 1, x, a, b, c; i <= T; ++i){scanf("%d %d %d %d", &x, &a, &b, &c);printf("Case #%d: %d\n", i, (LL)fact[2 * x] * inv[x] % p * inv[x + 1] % p);