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
#include <bits/stdc++.h>
#include "message.h"
#include "futbol.h"
#define ll long long

ll power(ll x, ll y, ll mod){
    if (y == 0)
        return 1;
    else if (y % 2 == 0){
        ll tmp = power(x, y/2, mod);
        return (tmp * tmp)%mod;
    }
    else
        return ((power(x, y-1, mod) * x)%mod);
}

int main(){

    ll myId = MyNodeId();
    if (myId != 0)  return 0;

    ll n = GetN();
    ll k = GetK();
    ll P = GetP();

    std::vector<ll> v;
    v.push_back(1); // C(n, 0)
    for (int i = 1; i <= k; i++){
        ll next = ((v[i-1] * (n-i+1))%P * power(i, P-2, P))%P;
        v.push_back(next);
    }
    ll res = 0;
    for (auto x: v)
        res = (res + x)%P;
    std::cout << res << "\n";
}