#include "Alice.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<pair<int, int>> Alice() {
const int kN = 5000;
ll x = setN(kN);
vector<pair<int, int>> edg;
for(int i = 1; i < kN; i++) {
edg.emplace_back(x % i + 1, i + 1);
}
return edg;
}
#include "Bob.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll Bob(vector<pair<int, int>> edg) {
const int kN = 5000;
const __uint128_t kX = 1e18;
array<bool, kN + 1> sieve;
fill(sieve.begin(), sieve.end(), true);
sieve[0] = sieve[1] = false;
for(int i = 4; i <= kN; i += 2) {
sieve[i] = false;
}
for(int i = 3; i * i <= kN; i += 2) {
if(sieve[i]) {
for(int j = i * i; j <= kN; j += 2 * i) {
sieve[j] = false;
}
}
}
__uint128_t p = 1;
vector<pair<int, int>> cong;
for(const auto &[a, m] : edg) {
if(sieve[m - 1]) {
cong.emplace_back(a - 1, m - 1);
p = p * (m - 1);
}
if(p > kX) {
break;
}
}
auto inv = [&](__uint128_t a, int m) -> __uint128_t {
a %= m;
int b = m - 2;
__uint128_t res = 1;
while(b) {
if(b & 1) {
res = res * a % m;
}
a = a * a % m;
b >>= 1;
}
return res;
};
__uint128_t res = 0;
for(const auto &[a, m] : cong) {
__uint128_t aux = p / m, n = inv(aux, m);
assert(n * aux % m == 1);
res = (res + a * aux % p * n) % p;
}
return (ll)res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
800 KB |
Correct. |
2 |
Correct |
2 ms |
804 KB |
Correct. |
3 |
Correct |
2 ms |
808 KB |
Correct. |
4 |
Correct |
2 ms |
752 KB |
Correct. |
5 |
Correct |
2 ms |
800 KB |
Correct. |
6 |
Correct |
2 ms |
812 KB |
Correct. |
7 |
Correct |
2 ms |
952 KB |
Correct. |
8 |
Correct |
2 ms |
804 KB |
Correct. |
9 |
Correct |
2 ms |
804 KB |
Correct. |
10 |
Correct |
2 ms |
804 KB |
Correct. |
11 |
Correct |
2 ms |
804 KB |
Correct. |
12 |
Correct |
2 ms |
800 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
800 KB |
Correct. |
2 |
Correct |
2 ms |
804 KB |
Correct. |
3 |
Correct |
2 ms |
808 KB |
Correct. |
4 |
Correct |
2 ms |
752 KB |
Correct. |
5 |
Correct |
2 ms |
800 KB |
Correct. |
6 |
Correct |
2 ms |
812 KB |
Correct. |
7 |
Correct |
2 ms |
952 KB |
Correct. |
8 |
Correct |
2 ms |
804 KB |
Correct. |
9 |
Correct |
2 ms |
804 KB |
Correct. |
10 |
Correct |
2 ms |
804 KB |
Correct. |
11 |
Correct |
2 ms |
804 KB |
Correct. |
12 |
Correct |
2 ms |
800 KB |
Correct. |
13 |
Correct |
3 ms |
804 KB |
Correct. |
14 |
Correct |
2 ms |
800 KB |
Correct. |
15 |
Correct |
2 ms |
780 KB |
Correct. |
16 |
Correct |
3 ms |
804 KB |
Correct. |
17 |
Correct |
2 ms |
804 KB |
Correct. |
18 |
Correct |
3 ms |
804 KB |
Correct. |
19 |
Correct |
3 ms |
816 KB |
Correct. |
20 |
Correct |
3 ms |
804 KB |
Correct. |
21 |
Correct |
2 ms |
804 KB |
Correct. |
22 |
Correct |
3 ms |
804 KB |
Correct. |
23 |
Correct |
2 ms |
776 KB |
Correct. |
24 |
Correct |
3 ms |
804 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
800 KB |
Correct. |
2 |
Correct |
2 ms |
804 KB |
Correct. |
3 |
Correct |
2 ms |
808 KB |
Correct. |
4 |
Correct |
2 ms |
752 KB |
Correct. |
5 |
Correct |
2 ms |
800 KB |
Correct. |
6 |
Correct |
2 ms |
812 KB |
Correct. |
7 |
Correct |
2 ms |
952 KB |
Correct. |
8 |
Correct |
2 ms |
804 KB |
Correct. |
9 |
Correct |
2 ms |
804 KB |
Correct. |
10 |
Correct |
2 ms |
804 KB |
Correct. |
11 |
Correct |
2 ms |
804 KB |
Correct. |
12 |
Correct |
2 ms |
800 KB |
Correct. |
13 |
Correct |
3 ms |
804 KB |
Correct. |
14 |
Correct |
2 ms |
800 KB |
Correct. |
15 |
Correct |
2 ms |
780 KB |
Correct. |
16 |
Correct |
3 ms |
804 KB |
Correct. |
17 |
Correct |
2 ms |
804 KB |
Correct. |
18 |
Correct |
3 ms |
804 KB |
Correct. |
19 |
Correct |
3 ms |
816 KB |
Correct. |
20 |
Correct |
3 ms |
804 KB |
Correct. |
21 |
Correct |
2 ms |
804 KB |
Correct. |
22 |
Correct |
3 ms |
804 KB |
Correct. |
23 |
Correct |
2 ms |
776 KB |
Correct. |
24 |
Correct |
3 ms |
804 KB |
Correct. |
25 |
Correct |
2 ms |
804 KB |
Correct. |
26 |
Correct |
2 ms |
800 KB |
Correct. |
27 |
Correct |
2 ms |
804 KB |
Correct. |
28 |
Correct |
2 ms |
804 KB |
Correct. |
29 |
Correct |
2 ms |
804 KB |
Correct. |
30 |
Correct |
2 ms |
808 KB |
Correct. |
31 |
Correct |
3 ms |
804 KB |
Correct. |
32 |
Correct |
3 ms |
756 KB |
Correct. |
33 |
Correct |
3 ms |
808 KB |
Correct. |
34 |
Correct |
2 ms |
944 KB |
Correct. |
35 |
Correct |
3 ms |
804 KB |
Correct. |
36 |
Correct |
3 ms |
816 KB |
Correct. |
37 |
Correct |
3 ms |
804 KB |
Correct. |
38 |
Correct |
2 ms |
724 KB |
Correct. |
39 |
Correct |
3 ms |
808 KB |
Correct. |
40 |
Correct |
2 ms |
804 KB |
Correct. |
41 |
Correct |
2 ms |
804 KB |
Correct. |
42 |
Correct |
3 ms |
776 KB |
Correct. |
43 |
Correct |
2 ms |
804 KB |
Correct. |
44 |
Correct |
2 ms |
976 KB |
Correct. |