Submission #1010585

#TimeUsernameProblemLanguageResultExecution timeMemory
1010585sleepntsheepMagic Show (APIO24_show)C++17
0 / 100
2 ms836 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)) * */ inline long long normalize(long long x, long long mod) { x %= mod; if (x < 0) x += mod; return x; } long long Bob(std::vector<std::pair<int,int>> T) { ii n1 = 1, a1 = 0; for (auto [u, v] : T) { if (u > v) std::swap(u, v); --u; --v; /* x = u (mod v) */ ii n2 = v, a2 = u; auto [s1, _, d] = exgcd(n1, n2); a1 = normalize(a1 + s1 * (a2 - a1) / d % (n2 / d) * n1, n1 * n2 / d); n1 = lcm(n1, n2); if (n1 > 1e18) return a1; } return (long long)a1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...