#include "message.h" #include "futbol.h" #include "bits/stdc++.h" #include <sys/time.h> #include <sys/resource.h> /* int GetN() { if (MyNodeId() != 0) return 0; return 949999999; } int GetK() { return 949999998; } int GetP() { return 999287789; } */ using namespace std; #ifdef LOCAL template<class T, class U> ostream& operator<<(ostream& os, pair<T, U> p) { return os << "(" << p.first << ", " << p.second << ")"; } template<class C, class = typename C::value_type> typename enable_if<!is_same<C, string>::value, ostream&>::type operator<<(ostream& os, C c) { for (auto i = c.begin(); i != c.end(); i++) { os << " {"[i == c.begin()] << *i << ",}"[next(i) == c.end()]; } return os; } #define debug(x) { cerr << #x << " = " << x << endl; } #else #define debug(...) {} #endif //TODO USTAW 1e9 const int N = 1e9; //const int N = 20; const int BLOCK = 20; //const int BLOCK = 4; const int INST = 100; int n; int id; int k, p, mod; typedef long long ll; namespace parts { int get_n(int i) { if (i == BLOCK - 1) return N; return (N / BLOCK) * (i+1); } int get_k() { return k; } int start(int i) { if (i == 0) return 1; return (get_k() / (INST - 1)) * (i-1) + 1; } int koniec(int i) { if (i == 0) return 1; if (i == INST - 1) return get_k() + 1; return (get_k() / (INST - 1)) * i + 1; } } namespace matma { int pot(int n, int k) { long long res = 1; long long b = n; for (int i = 0; (1<<i) <= k; i ++) { if ((1<<i) & k) { res = (res * b) % p; } b = (b * b) % p; } return res; } int odwr(int x) { return pot(x, p - 2); } } namespace sol { int silnia_zak(int a, int b) { long long res = 1; for (int i = a; i <= b; i ++) { res = (res * i) % p; } return res; } int silnia() { return silnia_zak(parts::start(id), parts::koniec(id) - 1); } int newt_mem; int newton(int sil) { int st = parts::start(id); int kon = parts::koniec(id); long long res = 1; long long sum = 0; vector<int> ss = {matma::odwr(sil)}; for (int j = kon - 1; j > st; j --) { ss.push_back((ss.back() * (ll)j) % p); } reverse(ss.begin(), ss.end()); // cerr << "sil = " << sil << " st = " << st << " kon = " << kon << "\n{ "; // for (int x : ss) { // cerr << x << ", "; // } // cerr << " }\n"; for (int j = st; j < kon; j ++) { res = (res * (n-j+1)) % mod; sum = (sum + (res * ss[j-st])) % mod; // cerr << "res = " << res << "\n"; } if (kon > st) newt_mem = (res * ss[kon - st - 1]) % mod; else newt_mem = 1; // cerr <<"sum = " << sum <<" res = " << res << " newt_mem = " << newt_mem << "\n"; return sum; } vector<long long> newt_calc; vector<int> newt_sum_calc; int sil_calc; void licz_newton_slave() { int st = parts::start(id); int kon = parts::koniec(id); for (int i = 0; i < BLOCK; i ++) { newt_calc.push_back(1); } for (int i = 0; i < BLOCK; i ++) { newt_sum_calc.push_back(0); } int sil = silnia_zak(st, kon - 1); vector<int> ss = {matma::odwr(sil)}; for (int j = kon - 1; j > st; j --) { ss.push_back((ss.back() * (ll)j) % p); } reverse(ss.begin(), ss.end()); if (id == INST - 1) debug(ss); for (int j = st; j < kon; j ++) { long long sumka = 0; for (int i = 0; i < BLOCK; i ++) { newt_calc[i] = (newt_calc[i] * (ll)(parts::get_n(i)-j+1)) % mod; newt_sum_calc[i] = (newt_sum_calc[i] + newt_calc[i] * (ll)ss[j - st]) % mod; } if (id == INST - 1) { debug(j); debug(newt_sum_calc); debug(newt_calc); } } if (kon > st) { for (auto &x : newt_calc) x = (x * (ll)ss[kon - 1 - st]) % mod; } if (id == INST - 1) { debug(newt_sum_calc); debug(newt_calc); } sil_calc = sil; } void slave_instance() { if (n == 0) { PutInt(0, -1); licz_newton_slave(); for (int x : newt_sum_calc) { PutInt(0, x); } for (int x : newt_calc) { PutInt(0, x); } PutInt(0, sil_calc); Send(0); return; } int s = silnia(); PutInt(0, newton(s)); PutInt(0, newt_mem); Send(0); } void read_data_from_slave(vector<vector<int>>& newt_sum, vector<vector<int>>& newt, vector<int>& sil) { for (int i = 0; i < BLOCK; i ++) { vector<int> v; for (int j = 1; j < INST; j ++) { v.push_back(GetInt(j)); } newt_sum.push_back(v); } debug(newt_sum); for (int i = 0; i < BLOCK; i ++) { vector<int> v; for (int j = 1; j < INST; j ++) { v.push_back(GetInt(j)); } for (int j = 1; j < v.size(); j ++) { v[j] = (v[j-1] * (long long)v[j]) % mod; newt_sum[i][j] = (newt_sum[i][j] * (long long)v[j-1] + newt_sum[i][j-1]) % mod; } newt.push_back(v); } for (int j = 1; j < INST; j ++) { sil.push_back(GetInt(j)); } for (int i = 1; i < sil.size(); i ++) { sil[i] = (sil[i-1] * (long long)sil[i]) % mod; } // debug(newt_sum); // debug(newt); debug(sil); } vector<int> pref; void main_preprocess() { int n_licz = n % (N / BLOCK); long long res = 1; int sil = silnia_zak(2, min(n_licz, k)); pref.resize(min(n_licz, k) + 1); pref[0] = matma::odwr(sil); int idx = 1; for (int j = min(n_licz, k); j > 1; j --) { pref[idx] = (pref[idx - 1] * (ll)j) % p; idx ++; } if (pref.size() == 1) idx = 0; pref[idx] = 1; debug(pref.size()); debug(idx + 1); assert(pref.size() == idx + 1); // cerr << "declared\n"; int pid = pref.size() - 2; for (int i = 1; i <= min(k, n_licz); i ++) { res = (res * (n_licz - i + 1)) % p; pref[pid] = (res * pref[pid]) % p; pid --; } reverse(pref.begin(), pref.end()); debug(n_licz); // debug(pref); } void get_odwr(vector<int>& ss, int W, int id, vector<int>& sil, vector<int>& newt) { id --; long long ilo = (newt[id] * (ll)sil[id]) % p; debug(ilo); debug(sil[id]); debug(newt[id]); debug(id); debug(parts::koniec(id + 1)); debug(parts::start(id+1)); long long odwr_ilo = matma::odwr(ilo); int wkk = parts::koniec(id + 1) - 1; int wkj = parts::start(id + 1); if (id != 0) { long long ilo2 = (newt[id-1] * (ll)sil[id-1]) % p; odwr_ilo = (ilo2 * odwr_ilo) % p; } ss.resize(max(1, wkk - wkj + 1)); ss[0] = odwr_ilo; int ssid = 1; if (W - wkk + 1 <= 0 && W - (wkj + 1) + 1 > 0) { // cerr << "first\n"; for (int i = wkk; i > wkj; i --) { if (W - i + 1 < 0) { ss[ssid] = 0; } else if (W - i + 1 == 0) { long long tmp = 1; for (int j = wkj; j < i; j ++) { tmp = (tmp * (W - j + 1)) % p; } debug("kurwa"); debug(tmp); ss[ssid] = matma::odwr(tmp); } else { ss[ssid] = (ss[ssid - 1] * (ll)(W - i + 1)) % p; } ssid ++; } } else { // cerr << "second\n"; // long long tmp = 1; // for (int k = parts::start(id + 1); k < parts::koniec(id + 1); k ++) { // tmp = (tmp * (W - k + 1)) % p; // } // debug(tmp); debug(odwr_ilo); // assert((tmp * odwr_ilo) % p == 1); for (int i = wkk; i > wkj; i --) { ss[ssid] = (ss[ssid - 1] * (ll)(W - i + 1)) % p; ssid ++; } } debug(ssid); debug(ss.size()); // cerr << ssid << "\n"; // cerr << ss.size() << "\n"; assert(ssid == ss.size()); reverse(ss.begin(), ss.end()); long long smno = 1; int iter = 1; for (int i = wkj; i < wkk; i ++) { smno = (smno * (ll)(W - i + 1)) % p; ss[iter] = (ss[iter] * smno) % p; iter ++; } // cerr << ss.back() << "\n"; // cerr << wkj << "\n"; // cerr << p <<"\n"; // cerr << (ss.back() * (ll)wkj) % p <<"\n"; // assert(ss.back() == 1); // return ss; } void dokoncz_sam() { vector<vector<int>> newt_sum, newt; vector<int> sil; read_data_from_slave(newt_sum, newt, sil); long long sum = 0; int blocks = n / (N / BLOCK); if (blocks == 0) { for (int x : pref) { sum += x; } } else { int W = blocks * (N / BLOCK); long long Wk_sum = (newt_sum[blocks - 1].back() + 1); debug(Wk_sum); long long Wk = newt[blocks - 1].back(); vector<int> ss; get_odwr(ss, W, INST - 1, sil, newt[blocks - 1]); int inst = INST - 1; int wkk = parts::koniec(INST - 1) - 1; int wkj = parts::start(INST - 1); debug(pref); debug(ss); // vector<int> smno({1}); // for (int x : ss) { // debug(matma::odwr(x)); // } debug((ll)ss.back() % p); // TODO NAPISAĆ KURWA MNOŻENIE ZAMIAST KURWA ODWROTNOŚCI for (int i = 0; i < pref.size(); i ++) { sum += (pref[i] * Wk_sum) % p; Wk_sum = (Wk_sum - Wk) % p; debug(Wk); debug(Wk_sum); Wk = (Wk * (k - i)) % p; // TODO napraw debug(ss.size()); debug(i); if (ss.size() == 0) { inst --; ss.clear(); get_odwr(ss, W, inst, sil, newt[blocks - 1]); wkk = parts::koniec(inst) - 1; wkj = parts::start(inst); } if (W - k + i + 1 > 0) Wk = (Wk * ss.back()) % p; ss.pop_back(); if (W - k + i + 1 == 0) Wk = 1; } } cout << ((sum % p) + p) % p << "\n"; } void dokoncz_wspolnie(vector<int> inne_newtony, vector<int> inne_newtony_sum) { long long sum = inne_newtony_sum[0]; for (int i = 1; i < inne_newtony.size(); i ++) { inne_newtony[i] = (inne_newtony[i-1] * (long long)inne_newtony[i]) % p; } // cerr <<inne_newtony[0] << "\n"; // cerr << inne_newtony[1] << "\n"; for (int i = 1; i < inne_newtony_sum.size(); i ++) { sum += (inne_newtony_sum[i] * (long long)inne_newtony[i-1]) % p; } cout << (sum + 1) % p << "\n"; } void main_instance() { int part_silnia = 1; vector<int> inne_newtony_sum(1, 0); vector<int> inne_newtony(1, 1); main_preprocess(); for (int i = 1; i < INST; i ++) { Receive(i); inne_newtony_sum.push_back(GetInt(i)); } if (inne_newtony_sum[1] == -1) dokoncz_sam(); else { for (int i = 1; i < INST; i ++) { inne_newtony.push_back(GetInt(i)); } dokoncz_wspolnie(inne_newtony, inne_newtony_sum); } } void solve() { if (id == 0) main_instance(); else slave_instance(); } } int main() { struct rlimit limit; limit.rlim_cur = 1024 * 1024 * 256; limit.rlim_max = 1024 * 1024 * 256; setrlimit(RLIMIT_AS, &limit); n = GetN(); k = GetK(), p = GetP(); mod = p; id = MyNodeId(); sol::solve(); }
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | #include "message.h" #include "futbol.h" #include "bits/stdc++.h" #include <sys/time.h> #include <sys/resource.h> /* int GetN() { if (MyNodeId() != 0) return 0; return 949999999; } int GetK() { return 949999998; } int GetP() { return 999287789; } */ using namespace std; #ifdef LOCAL template<class T, class U> ostream& operator<<(ostream& os, pair<T, U> p) { return os << "(" << p.first << ", " << p.second << ")"; } template<class C, class = typename C::value_type> typename enable_if<!is_same<C, string>::value, ostream&>::type operator<<(ostream& os, C c) { for (auto i = c.begin(); i != c.end(); i++) { os << " {"[i == c.begin()] << *i << ",}"[next(i) == c.end()]; } return os; } #define debug(x) { cerr << #x << " = " << x << endl; } #else #define debug(...) {} #endif //TODO USTAW 1e9 const int N = 1e9; //const int N = 20; const int BLOCK = 20; //const int BLOCK = 4; const int INST = 100; int n; int id; int k, p, mod; typedef long long ll; namespace parts { int get_n(int i) { if (i == BLOCK - 1) return N; return (N / BLOCK) * (i+1); } int get_k() { return k; } int start(int i) { if (i == 0) return 1; return (get_k() / (INST - 1)) * (i-1) + 1; } int koniec(int i) { if (i == 0) return 1; if (i == INST - 1) return get_k() + 1; return (get_k() / (INST - 1)) * i + 1; } } namespace matma { int pot(int n, int k) { long long res = 1; long long b = n; for (int i = 0; (1<<i) <= k; i ++) { if ((1<<i) & k) { res = (res * b) % p; } b = (b * b) % p; } return res; } int odwr(int x) { return pot(x, p - 2); } } namespace sol { int silnia_zak(int a, int b) { long long res = 1; for (int i = a; i <= b; i ++) { res = (res * i) % p; } return res; } int silnia() { return silnia_zak(parts::start(id), parts::koniec(id) - 1); } int newt_mem; int newton(int sil) { int st = parts::start(id); int kon = parts::koniec(id); long long res = 1; long long sum = 0; vector<int> ss = {matma::odwr(sil)}; for (int j = kon - 1; j > st; j --) { ss.push_back((ss.back() * (ll)j) % p); } reverse(ss.begin(), ss.end()); // cerr << "sil = " << sil << " st = " << st << " kon = " << kon << "\n{ "; // for (int x : ss) { // cerr << x << ", "; // } // cerr << " }\n"; for (int j = st; j < kon; j ++) { res = (res * (n-j+1)) % mod; sum = (sum + (res * ss[j-st])) % mod; // cerr << "res = " << res << "\n"; } if (kon > st) newt_mem = (res * ss[kon - st - 1]) % mod; else newt_mem = 1; // cerr <<"sum = " << sum <<" res = " << res << " newt_mem = " << newt_mem << "\n"; return sum; } vector<long long> newt_calc; vector<int> newt_sum_calc; int sil_calc; void licz_newton_slave() { int st = parts::start(id); int kon = parts::koniec(id); for (int i = 0; i < BLOCK; i ++) { newt_calc.push_back(1); } for (int i = 0; i < BLOCK; i ++) { newt_sum_calc.push_back(0); } int sil = silnia_zak(st, kon - 1); vector<int> ss = {matma::odwr(sil)}; for (int j = kon - 1; j > st; j --) { ss.push_back((ss.back() * (ll)j) % p); } reverse(ss.begin(), ss.end()); if (id == INST - 1) debug(ss); for (int j = st; j < kon; j ++) { long long sumka = 0; for (int i = 0; i < BLOCK; i ++) { newt_calc[i] = (newt_calc[i] * (ll)(parts::get_n(i)-j+1)) % mod; newt_sum_calc[i] = (newt_sum_calc[i] + newt_calc[i] * (ll)ss[j - st]) % mod; } if (id == INST - 1) { debug(j); debug(newt_sum_calc); debug(newt_calc); } } if (kon > st) { for (auto &x : newt_calc) x = (x * (ll)ss[kon - 1 - st]) % mod; } if (id == INST - 1) { debug(newt_sum_calc); debug(newt_calc); } sil_calc = sil; } void slave_instance() { if (n == 0) { PutInt(0, -1); licz_newton_slave(); for (int x : newt_sum_calc) { PutInt(0, x); } for (int x : newt_calc) { PutInt(0, x); } PutInt(0, sil_calc); Send(0); return; } int s = silnia(); PutInt(0, newton(s)); PutInt(0, newt_mem); Send(0); } void read_data_from_slave(vector<vector<int>>& newt_sum, vector<vector<int>>& newt, vector<int>& sil) { for (int i = 0; i < BLOCK; i ++) { vector<int> v; for (int j = 1; j < INST; j ++) { v.push_back(GetInt(j)); } newt_sum.push_back(v); } debug(newt_sum); for (int i = 0; i < BLOCK; i ++) { vector<int> v; for (int j = 1; j < INST; j ++) { v.push_back(GetInt(j)); } for (int j = 1; j < v.size(); j ++) { v[j] = (v[j-1] * (long long)v[j]) % mod; newt_sum[i][j] = (newt_sum[i][j] * (long long)v[j-1] + newt_sum[i][j-1]) % mod; } newt.push_back(v); } for (int j = 1; j < INST; j ++) { sil.push_back(GetInt(j)); } for (int i = 1; i < sil.size(); i ++) { sil[i] = (sil[i-1] * (long long)sil[i]) % mod; } // debug(newt_sum); // debug(newt); debug(sil); } vector<int> pref; void main_preprocess() { int n_licz = n % (N / BLOCK); long long res = 1; int sil = silnia_zak(2, min(n_licz, k)); pref.resize(min(n_licz, k) + 1); pref[0] = matma::odwr(sil); int idx = 1; for (int j = min(n_licz, k); j > 1; j --) { pref[idx] = (pref[idx - 1] * (ll)j) % p; idx ++; } if (pref.size() == 1) idx = 0; pref[idx] = 1; debug(pref.size()); debug(idx + 1); assert(pref.size() == idx + 1); // cerr << "declared\n"; int pid = pref.size() - 2; for (int i = 1; i <= min(k, n_licz); i ++) { res = (res * (n_licz - i + 1)) % p; pref[pid] = (res * pref[pid]) % p; pid --; } reverse(pref.begin(), pref.end()); debug(n_licz); // debug(pref); } void get_odwr(vector<int>& ss, int W, int id, vector<int>& sil, vector<int>& newt) { id --; long long ilo = (newt[id] * (ll)sil[id]) % p; debug(ilo); debug(sil[id]); debug(newt[id]); debug(id); debug(parts::koniec(id + 1)); debug(parts::start(id+1)); long long odwr_ilo = matma::odwr(ilo); int wkk = parts::koniec(id + 1) - 1; int wkj = parts::start(id + 1); if (id != 0) { long long ilo2 = (newt[id-1] * (ll)sil[id-1]) % p; odwr_ilo = (ilo2 * odwr_ilo) % p; } ss.resize(max(1, wkk - wkj + 1)); ss[0] = odwr_ilo; int ssid = 1; if (W - wkk + 1 <= 0 && W - (wkj + 1) + 1 > 0) { // cerr << "first\n"; for (int i = wkk; i > wkj; i --) { if (W - i + 1 < 0) { ss[ssid] = 0; } else if (W - i + 1 == 0) { long long tmp = 1; for (int j = wkj; j < i; j ++) { tmp = (tmp * (W - j + 1)) % p; } debug("kurwa"); debug(tmp); ss[ssid] = matma::odwr(tmp); } else { ss[ssid] = (ss[ssid - 1] * (ll)(W - i + 1)) % p; } ssid ++; } } else { // cerr << "second\n"; // long long tmp = 1; // for (int k = parts::start(id + 1); k < parts::koniec(id + 1); k ++) { // tmp = (tmp * (W - k + 1)) % p; // } // debug(tmp); debug(odwr_ilo); // assert((tmp * odwr_ilo) % p == 1); for (int i = wkk; i > wkj; i --) { ss[ssid] = (ss[ssid - 1] * (ll)(W - i + 1)) % p; ssid ++; } } debug(ssid); debug(ss.size()); // cerr << ssid << "\n"; // cerr << ss.size() << "\n"; assert(ssid == ss.size()); reverse(ss.begin(), ss.end()); long long smno = 1; int iter = 1; for (int i = wkj; i < wkk; i ++) { smno = (smno * (ll)(W - i + 1)) % p; ss[iter] = (ss[iter] * smno) % p; iter ++; } // cerr << ss.back() << "\n"; // cerr << wkj << "\n"; // cerr << p <<"\n"; // cerr << (ss.back() * (ll)wkj) % p <<"\n"; // assert(ss.back() == 1); // return ss; } void dokoncz_sam() { vector<vector<int>> newt_sum, newt; vector<int> sil; read_data_from_slave(newt_sum, newt, sil); long long sum = 0; int blocks = n / (N / BLOCK); if (blocks == 0) { for (int x : pref) { sum += x; } } else { int W = blocks * (N / BLOCK); long long Wk_sum = (newt_sum[blocks - 1].back() + 1); debug(Wk_sum); long long Wk = newt[blocks - 1].back(); vector<int> ss; get_odwr(ss, W, INST - 1, sil, newt[blocks - 1]); int inst = INST - 1; int wkk = parts::koniec(INST - 1) - 1; int wkj = parts::start(INST - 1); debug(pref); debug(ss); // vector<int> smno({1}); // for (int x : ss) { // debug(matma::odwr(x)); // } debug((ll)ss.back() % p); // TODO NAPISAĆ KURWA MNOŻENIE ZAMIAST KURWA ODWROTNOŚCI for (int i = 0; i < pref.size(); i ++) { sum += (pref[i] * Wk_sum) % p; Wk_sum = (Wk_sum - Wk) % p; debug(Wk); debug(Wk_sum); Wk = (Wk * (k - i)) % p; // TODO napraw debug(ss.size()); debug(i); if (ss.size() == 0) { inst --; ss.clear(); get_odwr(ss, W, inst, sil, newt[blocks - 1]); wkk = parts::koniec(inst) - 1; wkj = parts::start(inst); } if (W - k + i + 1 > 0) Wk = (Wk * ss.back()) % p; ss.pop_back(); if (W - k + i + 1 == 0) Wk = 1; } } cout << ((sum % p) + p) % p << "\n"; } void dokoncz_wspolnie(vector<int> inne_newtony, vector<int> inne_newtony_sum) { long long sum = inne_newtony_sum[0]; for (int i = 1; i < inne_newtony.size(); i ++) { inne_newtony[i] = (inne_newtony[i-1] * (long long)inne_newtony[i]) % p; } // cerr <<inne_newtony[0] << "\n"; // cerr << inne_newtony[1] << "\n"; for (int i = 1; i < inne_newtony_sum.size(); i ++) { sum += (inne_newtony_sum[i] * (long long)inne_newtony[i-1]) % p; } cout << (sum + 1) % p << "\n"; } void main_instance() { int part_silnia = 1; vector<int> inne_newtony_sum(1, 0); vector<int> inne_newtony(1, 1); main_preprocess(); for (int i = 1; i < INST; i ++) { Receive(i); inne_newtony_sum.push_back(GetInt(i)); } if (inne_newtony_sum[1] == -1) dokoncz_sam(); else { for (int i = 1; i < INST; i ++) { inne_newtony.push_back(GetInt(i)); } dokoncz_wspolnie(inne_newtony, inne_newtony_sum); } } void solve() { if (id == 0) main_instance(); else slave_instance(); } } int main() { struct rlimit limit; limit.rlim_cur = 1024 * 1024 * 256; limit.rlim_max = 1024 * 1024 * 256; setrlimit(RLIMIT_AS, &limit); n = GetN(); k = GetK(), p = GetP(); mod = p; id = MyNodeId(); sol::solve(); } |