Submission #1010573

#TimeUsernameProblemLanguageResultExecution timeMemory
1010573sleepntsheepMagic Show (APIO24_show)C++17
0 / 100
3 ms820 KiB
#include <vector> #include "Alice.h" std::vector<std::pair<int,int>> Alice(){ long long x = setN(5000); std::vector<std::pair<int, int > > T = {}; for (int i = 2; i <= 5000; ++i) T.emplace_back( (x % (i - 1) + 1), i); return T; }
#include <vector> #include <cstdio> #include <algorithm> #include <array> #include "Bob.h" using ii = __int128; template <typename T> std::array<T, 3> exgcd(T x, T y) { if (y == 0) return {x, 0, x}; auto [s1, t1, d] = exgcd(y, x % y); T s, t; s = t1; t = s1 - t1 * (x / y); return {s, t, d}; } ii lcm(long long x, long long y) { auto [_, __, d] = exgcd(x, y); return (x / d) * y; } /* * * CRT * * * x = a1 (mod n1) * x = a2 (mod n2) * * x = a1 + k1n1 * = a2 + k2n2 * * k2n2 - k1n1 = a1 - a2 * * d = gcd(n1, n2) * let e = (a1 - a2) / d * * find s, t * such that * * n1s + n2t = d * * then x = a1 + n1 (se) * = a2 + n2 (te) * * and new equation x = (sth) (mod lcm(n1, n2)) * */ long long Bob(std::vector<std::pair<int,int>> T) { ii x = 0, n1 = 1, a1 = 0; for (auto [u, v] : T) { if (u > v) std::swap(u, v); if (v == 1)continue; --u; --v; /* x = u (mod v) */ ii n2 = v, a2 = u; auto [s1, t1, d] = exgcd(n1, n2); ii e = (a1 - a2) / d; ii cm = lcm(n1, n2); x = (a1 + (s1 * (-e) % (n2 / d) * n1 % cm)) % cm; n1 = cm; a1 = x % n1; if (n1 > 1e18) return x; } return (long long)x; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...