| 252 | } |
| 253 | |
| 254 | bool is_primitive_root_naive(int m, int g) { |
| 255 | assert(1 <= g && g < m); |
| 256 | auto prs = factors(m - 1); |
| 257 | int x = 1; |
| 258 | for (int i = 1; i <= m - 2; i++) { |
| 259 | x = (int)((long long)(x)*g % m); |
| 260 | // x == n^i |
| 261 | if (x == 1) return false; |
| 262 | } |
| 263 | x = (int)((long long)(x)*g % m); |
| 264 | assert(x == 1); |
| 265 | return true; |
| 266 | } |