random_device rd; mt19937 rng(rd()); ll primary_root(ll p) { uniform_int_distribution 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; } }