blob: 44f88c16a87adfaec269d6336004d4a96e811397 (
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
40
41
42
43
|
#include "../util.h"
#define ll lll
#include <math/modPowIterativ.cpp>
#undef ll
#include <math/legendre.cpp>
void stress_test() {
ll work = 0;
for (ll i = 0; i < 5'000; i++) {
ll p = Random::prime<ll>(5'000);
vector<bool> isSquare(p);
for (ll j = 1; j < p; j++) isSquare[(j*j) % p] = true;
for (ll j = 0; j < p; j++) {
auto got = legendre(j, p);
auto expected = j == 0 ? 0 : (isSquare[j] ? 1 : -1);
if (got != expected) cerr << "error: " << j << " " << p << FAIL;
}
work += p;
}
cerr << "stress tested: " << work << endl;
}
constexpr int N = 1'000'000;
constexpr ll mod = 1'394'633'899;
void performance_test() {
timer t;
hash_t hash = 0;
for (int operations = 0; operations < N; operations++) {
ll j = Random::integer<ll>(mod);
t.start();
hash += legendre(j, mod);
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();
if (!sanitize) performance_test();
}
|