Given p, k, a, where p, k is a prime number, x ^ k = a (mod p ). The legendary much simpler task .... If r is the original root of p (all prime numbers have the original root), then r ^ 1, r ^ 2... r ^ phi (p) constitutes the complete Residue System of the modulo p, so x = r ^ I, a = r ^ j can be set, then the equation is converted into r ^ (I * k) = r ^ j (mod p) then the theorem can obtain I * k = j (mod P-1) the r ^ j = a mod p can be obtained from the discrete logarithm. j can be obtained from the I * k = j mod P-1 by the modulus linear equation. x is sorted after the remainder is obtained, output. [Cpp] # include <map> # include <cstdio> # include <cmath> # include <vector> # include <iostream> # include <algorithm> using namespace std; typedef long ll; vector <ll> f, as; ll pow (ll a, ll B, ll mod) {ll as = 1; while (B) {if (B & 1) as = (as * a) % mod; a = (a * a) % mod; B >>= 1;} return ;} bool g_test (ll g, ll p) {for (ll I = 0; I <f. size (); I ++) if (pow (g, (p-1)/f [I], p) = 1) return 0; return 1 ;} ll yuangen (ll p) {f. clear (); ll Tmp = p-1; for (ll I = 2; I <= tmp/I; I ++) if (tmp % I = 0) {f. push_back (I); while (tmp % I = 0) tmp/= I;} if (tmp! = 1) f. push_back (tmp); ll g = 0; while (++ g) if (g_test (g, p) return g;} ll discrete_log (ll x, ll n, ll m) {// x ^ y = n (mod m) Evaluate y map <ll, int> rec; ll s = (ll) (sqrt (m) + 0.5 ); ll cur = 1; for (int I = 0; I <s; I ++) {rec [cur] = I; cur = cur * x % m ;} ll mul = cur; cur = 1; for (int I = 0; I <s; I ++) {ll more = n * pow (cur, m-2, m) % m; if (rec. count (more) return I * s + rec [more]; cur = cur * mul % m;} return-1;} ll ex_gcd (ll a, ll B, ll & x, ll & y) {if (B = 0) {X = 1; y = 0; return a;} else {ll r = ex_gcd (B, a % B, y, x ); y-= x * (a/B); return r ;}} void line_mod_equation (ll a, ll B, ll n) {// ax = B (mod n) returns x ll x, y, d;. clear (); d = ex_gcd (a, n, x, y); if (B % d = 0) {x % = n; x + = n; x % = n;. push_back (x * (B/d) % (n/d); for (ll I = 1; I <d; I ++). push_back (as [0] + I * n/d) % n) ;}} int main () {ll a, k, p, g, q; while (~ Scanf ("% lld", & p, & k, & a) {if (a = 0) {puts ("1 \ n0 "); continue;} // a = 0 Criterion g = yuangen (p); q = discrete_log (g, a, p); line_mod_equation (k, q, P-1 ); for (int I = 0; I <. size (); I ++) as [I] = pow (g, as [I], p); sort (. begin (),. end (); printf ("% d \ n",. size (); for (int I = 0; I <. size (); I ++) printf ("% lld % c", as [I], I =. size ()-1? '\ N': '');} return 0 ;}