[BAILIAN] hihoCoder Challenge 35 register

Ended

Participants:163

Verdict:Accepted
Submitted:2018-08-26 18:33:03

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define maxn 10010
using 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);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX