blob: 565989c57d330e9a934d994457acb00e2be19aa6 (
plain)
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
|
#include "../util.h"
#include <math/shortModInv.cpp>
void stress_test() {
ll queries = 0;
for (int i = 0; i < 10'000'000; i++) {
ll n = Random::integer<ll>(2, 1'000'000'000);
ll x = 0;
do {
x = Random::integer<ll>(0, 1'000'000'000);
} while (gcd(x, n) != 1);
ll y = multInv(x, n);
ll got = (x*y) % n;
if (got != 1) cerr << "got: " << got << ", expected: 1" << FAIL;
queries++;
}
cerr << "tested queries: " << queries << endl;
}
constexpr int N = 1'000'000;
void performance_test() {
timer t;
hash_t hash = 0;
for (int operations = 0; operations < N; operations++) {
ll a = Random::integer<ll>(0, 1'000'000'000);
ll b = Random::integer<ll>(2, 1'000'000'000);
t.start();
hash += multInv(a, b);
t.stop();
}
if (t.time > 750) cerr << "too slow: " << t.time << FAIL;
cerr << "tested performance: " << t.time << "ms (hash: " << hash << ")" << endl;
}
int main() {
stress_test();
performance_test();
}
|