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
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
#include"message.h"
#include"futbol.h"
using namespace std;
typedef long long int lld;

const lld SIZE = 1e6;

lld P;

lld fastPow(lld a, lld b){
	if(b == 0)
		return 1ll;

	if(b%2 == 1)
		return (a*fastPow(a,b-1)) % P;

	lld w = fastPow(a,b/2);

	return (w*w) % P;
}

lld inv(lld x){
	return fastPow(x,P-2);
}

lld brt(lld a, lld b){
	lld tmp = 1;
	lld res = 0;
	lld n = GetN();
	b = min(b, (lld) GetK());

	for(lld i=a;i<=b;i++){
		res = (res+tmp) % P;
		tmp = (tmp * (((n-i) * inv(i+1)) % P )) % P;
	}

	return res;
}

int main(void){
	P = GetP();

	if(GetK() <= 1e6){
		if(MyNodeId() == 0)
			cout << brt(0, GetK()) << "\n";
		return 0;
	}

	int nr = 0;
	lld res = brt(nr*SIZE+1, (nr+1)*SIZE);

	if(MyNodeId() != 0){
		PutLL(0,res);
		Send(0);
		return 0;
	}

	for(int i=1;i<100;i++){
		Receive(i);
		res = (res + GetLL(i)) % P;
	}

	cout << res << "\n";

	return 0;
}