#P5668. Modular Equation Solver
Modular Equation Solver
Modular Equation Solver
Given three integers n, k, and m, solve the modular equation:
$$x^n \equiv k \pmod{m}$$
where x is an integer in the range [0, m-1]. If there exist one or more solutions, output all such values in ascending order separated by a single space. Otherwise, output -1.
inputFormat
The input consists of a single line containing three space-separated integers: n, k, and m.
outputFormat
Output all integers x in the range [0, m-1] satisfying the equation $$x^n \equiv k \pmod{m}$$ in ascending order, separated by a single space. If no solution exists, output -1.
sample
2 4 6
2 4