Skip to content

Commit a3b98a0

Browse files
committed
fix a bug on primitive-root
1 parent 173adc8 commit a3b98a0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mathematics/primitive-root.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ bool test(LL g, LL n, LL phi, std::vector<LL> &u) {
77
return true;
88
}
99
LL primitive_root(LL n) {
10-
LL phi = euler_phi(n), m = n;
10+
LL phi = euler_phi(n), m = phi;
1111
std::vector<LL> u;
12-
for (LL i = 2; i * i <= m; ++i) if (n % i == 0) {
12+
for (LL i = 2; i * i <= m; ++i) if (m % i == 0) {
1313
u.push_back(i);
14-
while (n % i == 0) n /= i;
14+
while (m % i == 0) m /= i;
1515
}
16-
if (n > 1) u.push_back(n);
16+
if (m > 1) u.push_back(m);
1717
for (int g = 1; ; ++g) {
18-
if (test(g, m, phi, u)) return g;
18+
if (test(g, n, phi, u)) return g;
1919
}
2020
return -1;
2121
}

0 commit comments

Comments
 (0)