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
57
58
59
#include <bits/stdc++.h>
#include "message.h"
#include "futbol.h"
using namespace std;

typedef long long ll;

ll N, K, mod;

ll fast_pow(ll a, ll exp)
{
	if(exp == 0)
		return 1LL;
	ll temp = fast_pow(a, exp / 2);
	temp = temp * temp % mod;
	if(exp & 1)	
		temp = temp * a % mod;
	return temp;
}

const int maxn = 5000000;

ll silnie[maxn];
ll odwr[maxn];

int main()
{
	if(MyNodeId() != 0)
		return 0;
		
	N = GetN();
	K = GetK();
	mod = GetP(); 
	
	if(N >= maxn)
	{
		cout << 0 << "\n";
		return 0;
	}
		
	silnie[0] = 1;
	odwr[0] = 1;
	for(int i = 1; i <= N; i++)
	{
		silnie[i] = silnie[i - 1] * i % mod;
		odwr[i] = fast_pow(silnie[i], mod - 2);
	}
	
	ll ans = 0;
	for(int i = 0; i <= K; i++)
	{
		ll temp = (silnie[N] * odwr[i] % mod) * odwr[N - i];
		ans = (ans + temp) % mod;
	}
	
	cout << ans << endl;
	
	return 0;
}