#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
820 KB |
Correct. |
2 |
Correct |
1 ms |
820 KB |
Correct. |
3 |
Correct |
1 ms |
836 KB |
Correct. |
4 |
Correct |
2 ms |
832 KB |
Correct. |
5 |
Correct |
2 ms |
828 KB |
Correct. |
6 |
Correct |
2 ms |
820 KB |
Correct. |
7 |
Correct |
1 ms |
820 KB |
Correct. |
8 |
Correct |
1 ms |
820 KB |
Correct. |
9 |
Correct |
1 ms |
820 KB |
Correct. |
10 |
Correct |
2 ms |
820 KB |
Correct. |
11 |
Incorrect |
2 ms |
820 KB |
Incorrect answer. |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
820 KB |
Correct. |
2 |
Correct |
1 ms |
820 KB |
Correct. |
3 |
Correct |
1 ms |
836 KB |
Correct. |
4 |
Correct |
2 ms |
832 KB |
Correct. |
5 |
Correct |
2 ms |
828 KB |
Correct. |
6 |
Correct |
2 ms |
820 KB |
Correct. |
7 |
Correct |
1 ms |
820 KB |
Correct. |
8 |
Correct |
1 ms |
820 KB |
Correct. |
9 |
Correct |
1 ms |
820 KB |
Correct. |
10 |
Correct |
2 ms |
820 KB |
Correct. |
11 |
Incorrect |
2 ms |
820 KB |
Incorrect answer. |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
820 KB |
Correct. |
2 |
Correct |
1 ms |
820 KB |
Correct. |
3 |
Correct |
1 ms |
836 KB |
Correct. |
4 |
Correct |
2 ms |
832 KB |
Correct. |
5 |
Correct |
2 ms |
828 KB |
Correct. |
6 |
Correct |
2 ms |
820 KB |
Correct. |
7 |
Correct |
1 ms |
820 KB |
Correct. |
8 |
Correct |
1 ms |
820 KB |
Correct. |
9 |
Correct |
1 ms |
820 KB |
Correct. |
10 |
Correct |
2 ms |
820 KB |
Correct. |
11 |
Incorrect |
2 ms |
820 KB |
Incorrect answer. |
12 |
Halted |
0 ms |
0 KB |
- |