#include<bits/stdc++.h>
#include "futbol.h"
#include "message.h"
#define ll long long
#define st first
#define nd second
#define mp make_pair
#define ld long double
#define pb push_back
using namespace std;
/*int GetP(){
int x;cin >>x; return x;
}
int GetK(){
int x;cin >>x; return x;
}
int GetN(){
int x;cin >>x; return x;
}*/
ll mod=GetP(),n=GetN(),k=GetK();
ll pot(ll x,ll kt){
if(kt==0){
return 1;
}
if(kt&1){
return x*pot(x,kt-1)%mod;
}
ll a=pot(x,kt/2);
return a*a%mod;
}
ll odw(ll co){
return pot(co,mod-2);
}
pair<ll,ll> roz(ll po,ll ko){
ll ter=1;
ll sum=1,i;
for(i=po;i<ko;i++){
ter*=n-i;
ter%=mod;
ter*=odw(i+1);
ter%=mod;
sum+=ter;
sum%=mod;
//cout <<ter <<"\n";
}
ter*=n-i;
ter%=mod;
ter*=odw(i+1);
ter%=mod;
return mp(sum,ter);
}
vector<pair<int,int> > podz(ld n,ld po,ld ko){
// wlacznie z poczatkiem i koncem
vector<pair<int,int> > vec;
for(ld i=0;i<n;i++){
vec.pb(mp(po+(ko-po)*(i/n),po+(ko-po)*((i+1)/n)-1));
}
vec[0].st=po;
vec[n-1].nd=ko;
return vec;
}
int main(){
int lp=min(100LL,k-1);
lp=max(1,lp);
vector<pair<int,int> > vec=podz(lp,0,k);
ll wyn=0;
ll pop=1;
//int me=0;
int me=MyNodeId();
ll tuw=0;
ll tuz=1;
if(me<vec.size()){
pair<ll,ll> pr=roz(vec[me].st,vec[me].nd);
tuw=pr.st;
tuz=pr.nd;
}
if(me!=0){
Receive(me-1);
wyn=GetLL(me-1);
pop=GetLL(me-1);
}
wyn=wyn+pop*tuw;
wyn%=mod;
pop=pop*tuz;
pop%=mod;
if(me==99){
cout <<wyn;
return 0;
}
PutLL(me+1,wyn);
PutLL(me+1,pop);
Send(me+1);
return 0;
}
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | #include<bits/stdc++.h> #include "futbol.h" #include "message.h" #define ll long long #define st first #define nd second #define mp make_pair #define ld long double #define pb push_back using namespace std; /*int GetP(){ int x;cin >>x; return x; } int GetK(){ int x;cin >>x; return x; } int GetN(){ int x;cin >>x; return x; }*/ ll mod=GetP(),n=GetN(),k=GetK(); ll pot(ll x,ll kt){ if(kt==0){ return 1; } if(kt&1){ return x*pot(x,kt-1)%mod; } ll a=pot(x,kt/2); return a*a%mod; } ll odw(ll co){ return pot(co,mod-2); } pair<ll,ll> roz(ll po,ll ko){ ll ter=1; ll sum=1,i; for(i=po;i<ko;i++){ ter*=n-i; ter%=mod; ter*=odw(i+1); ter%=mod; sum+=ter; sum%=mod; //cout <<ter <<"\n"; } ter*=n-i; ter%=mod; ter*=odw(i+1); ter%=mod; return mp(sum,ter); } vector<pair<int,int> > podz(ld n,ld po,ld ko){ // wlacznie z poczatkiem i koncem vector<pair<int,int> > vec; for(ld i=0;i<n;i++){ vec.pb(mp(po+(ko-po)*(i/n),po+(ko-po)*((i+1)/n)-1)); } vec[0].st=po; vec[n-1].nd=ko; return vec; } int main(){ int lp=min(100LL,k-1); lp=max(1,lp); vector<pair<int,int> > vec=podz(lp,0,k); ll wyn=0; ll pop=1; //int me=0; int me=MyNodeId(); ll tuw=0; ll tuz=1; if(me<vec.size()){ pair<ll,ll> pr=roz(vec[me].st,vec[me].nd); tuw=pr.st; tuz=pr.nd; } if(me!=0){ Receive(me-1); wyn=GetLL(me-1); pop=GetLL(me-1); } wyn=wyn+pop*tuw; wyn%=mod; pop=pop*tuz; pop%=mod; if(me==99){ cout <<wyn; return 0; } PutLL(me+1,wyn); PutLL(me+1,pop); Send(me+1); return 0; } |
English