N times remaining (hdu 3930) and remaining hdu3930
Remaining N times (hdu 3930)
Task:
Given N, a, p, obtain all the solutions (x ^ N) % p = a in the p-mode sense x.
Note:
Let g be the original root of p, Because p is a prime number, so phi (p) = p-1.
From the nature of the original root:
If g is the original root of p, then: g ^ I mod p! = G ^ j mod p (p is a prime number), where I! = J and I, j is between 1 and (pm)
Therefore, you can set g ^ y = x, g ^ t = a, then there are:
G ^ (y * N) % p = g ^ t
Also by the nature of the original root:
G ^ (y * N) % p = g ^ t-> (y * N) % (p-1) = t (this equation can be obtained by the expanded Euclidean)
In addition, g ^ t = a can be obtained from the discrete logarithm.
Question: hdu 3930
Question:
Given newx, k, m, equation (x ^ k) % m = newx, obtain all solutions x in the sense of m.
Restrictions:
0 <= newx, m, k <= 1.5*10 ^ 15; m is a prime number.