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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
#include "message.h"
#include "futbol.h"

using namespace std;

long long n, k, mod;

long long binpow(long long x, long long a) {
    if (a == 0) return 1LL;
    if (a & 1) {
        return x * binpow(x, a - 1) % mod;
    } else {
        long long t = binpow(x, a / 2);
        return t * t % mod;
    }
}

long long inverse(long long x) {
    return binpow(x, mod - 2);
}

int main() {
    int nodes = NumberOfNodes();
    int myNode = MyNodeId();

    if (myNode == 0) {
        n = GetN();
        k = GetK();
        mod = GetP();

        long long ans = 0;

        long long nf = 1;
        for (int i = 2; i <= n; i++) {
            nf = (nf * i) % mod;
        }

        long long nk = n;
        long long nkf = 1;
        for (int i = 2; i <= nk; i++) {
            nkf = (nkf * i) % mod;
        }

        long long curr = 1;
        for (int x = 0; x <= k; x++) {
            ans = (ans + curr) % mod;
            curr = curr * inverse(x+1) % mod;
            curr = curr * (n-x) % mod;
        }

        cout << ans << endl;
    }

    return 0;
}