/
barrett-reduction.test.cpp
67 lines (60 loc) · 1.38 KB
/
barrett-reduction.test.cpp
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
#define PROBLEM "https://judge.yosupo.jp/problem/aplusb"
//
#include "../../template/template.hpp"
//
#include "../../misc/rng.hpp"
#include "../../modint/arbitrary-modint.hpp"
using namespace Nyaan;
using mint = ArbitraryModInt;
void test(int m) {
mint::set_mod(m);
mint x = 1;
int y = 1;
rep(loop, TEN(3)) {
int z = randint(0, 2 * TEN(9));
if (rng() & 1) z = -z;
x *= z;
y = 1LL * y * z % m;
if (y < 0) y += m;
assert(x.x == y);
}
Barrett barrett(m);
// m!=1 で正しく動作するはず
if (m != 1) {
rep(loop, TEN(3)) {
u64 i = rng();
auto [quo, rem] = barrett.quorem(i);
assert(quo == barrett.quo(i));
assert(rem == barrett.rem(i));
i64 quo2 = i / m;
i64 rem2 = i % m;
assert(quo == quo2);
assert(rem == rem2);
}
}
rep(loop, TEN(3)) {
int p = randint(0, m);
long long e = randint(0, 10);
mint r1 = mint{p}.pow(e);
int r2 = barrett.pow(p, e);
/*
if (r1.get() != r2) {
cerr << p << " " << e << " " << m << endl;
cerr << r1 << " " << r2 << endl;
}
*/
assert(r1.get() == r2);
}
}
void Nyaan::solve() {
int mod_max = (1LL << 30) - 1;
rep1(m, 10) test(m);
test(998244353);
test(1000000007);
rep(t, 10) test(mod_max - t);
rep(i, TEN(4)) test(randint(1, mod_max + 1));
cerr << "OK" << endl;
int a, b;
cin >> a >> b;
cout << a + b << endl;
}