Files
teamnote/source/Math/PrimitiveRoot.cpp
T
2026-07-11 09:38:32 +09:00

21 lines
451 B
C++

random_device rd; mt19937 rng(rd());
ll primary_root(ll p) {
uniform_int_distribution<ll> dist(1, p-1);
auto gen = bind(dist, rng);
vl g = po_rho(p-1);
while(true) {
ll c = gen(), u = p-1, b = 1;
bool ok = true;
for(auto i:g) {
if(i != b) u = p-1;
ll x = pow(c, u/i, p);
if(x == 1) ok = false;
u /= i; b = i;
}
if(ok) return c;
}
}